Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

soft-assert

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

soft-assert

Soft Asserts JSON, Array and other data

  • 0.2.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
increased by12.34%
Maintainers
1
Weekly downloads
 
Created
Source

soft-assert

Soft Asserts the Json, Array and other data types. It throws an AssertionError when assertion fails in mocha test

Functions supported :

1.  deepAssert(actual, expected, msg, ignoreKeys)
2.  softAssert(actual, expected, msg, ignoreKeys)
3.  deepContains(actual, expected, msg, ignoreKeys)
4.  softContains(actual, expected, msg, ignoreKeys)
5.  deepAssertKey(actual, expected, key, msg, ignoreKeys)
6.  softAssertKey(actual, expected, key, msg, ignoreKeys)
7.  deepContainstKey(actual, expected, key, msg, ignoreKeys)
8.  softContainsKey(actual, expected, key, msg, ignoreKeys)
9.  deeptTrue(value, msg)
10. softTrue(value, msg)
11. deepAssertKeyAbsence(actual, key, msg)
12. softAssertKeyAbsence(actual, key, msg)
13. softAssertAll()

Example Test for Soft Assert

Using softAssert, softContains, softAssertKey, softTrue, softAssertKeyAbsence asserts the value but does not throws the AssertionError, until softAssertAll is called.

softAssertAll - throws the error of all the previous soft assertion's error if any

String comparison in deepContains and softContains of JSON/String/JSON Array also supports Regex. Refer Tests for sample

Sample Test Link

Example :

it("softAssert test", function() {
        let actual = _.cloneDeep(json);
        let expected = _.cloneDeep(json);
        jsonAssertion.softAssert(actual, expected, "assertion error for softAssert 1");
        expected.glossary.GlossDiv.GlossList2 = "something";
        jsonAssertion.softAssert(actual, expected, "assertion error for softAssert 2", ["GlossList2"]);
        expected.glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso = ["some2"];
        delete expected.glossary.GlossDiv.GlossList.GlossEntry.GlossDef.para;
        jsonAssertion.softAssert(actual, expected, "assertion error for softAssert 3");
        jsonAssertion.softAssert(actual, expected, "assertion error for softAssert 4");
        jsonAssertion.softAssertAll();
})

Sample Test Failure Screenshot :

Alt text

Keywords

FAQs

Package last updated on 26 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc