Socket
Socket
Sign inDemoInstall

assert-deep-strict-equal

Package Overview
Dependencies
0
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    assert-deep-strict-equal

Asynchronous assert fails in Mocha you can see and don't timeout


Version published
Weekly downloads
15
decreased by-37.5%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

assert-deep-strict-equal

<img src=https://centerkey.com/graphics/center-key-logo.svg align=right width=200 alt=logo>

Asynchronous assert fails in Mocha you can see and don't timeout

License:MIT npm Build

A) Setup

Install package for node:

$ npm install --save-dev assert-deep-strict-equal

Import into your Mocha spec file:

import { assertDeepStrictEqual } from 'assert-deep-strict-equal';

B) Usage

const actual =   { ingredient: 'sugar', units: 'grams', amount: 100 };
const expected = { ingredient: 'sugar', units: 'grams', amount: 100 };
assertDeepStrictEqual(actual, expected, done);

The third parameter for the done callback is optional:

assertDeepStrictEqual(actual, expected);  //synchronous test case

C) Example

describe('Star Wars API result for spaceship #3', () => {

   it('is a Star Destroyer', (done) => {
      const url = 'https://swapi.py4e.com/api/starships/3/';
      const handleData = (data) => {
         const actual = {
            name:         data.name,
            model:        data.model,
            manufacturer: data.manufacturer,
            };
         const expected = {
            name:         'Star Destroyer',
            model:        'Imperial I-class Star Destroyer',
            manufacturer: 'Kuat Drive Yards',
            };
         assertDeepStrictEqual(actual, expected, done);
         };
      fetchJson.get(url, { format: 'json' }).then(handleData);
      });

   });

Commands to run the above Star Destroyer example and others in examples.spec.js:

$ cd assert-deep-strict-equal
$ npm install
$ npm run examples

<img src=https://raw.githubusercontent.com/center-key/assert-deep-strict-equal/main/examples.png width=800 alt=screenshot> Note that the assertion failure does not cause a timeout and the test case error is easy to see and interpret.  The value of the name field is "BOGUS!" (red), but it was expected to be "payapa-berry" (green).



MIT License

Keywords

FAQs

Last updated on 06 Feb 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc