1.2.0 • Published 3 months ago

assert-deep-strict-equal v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

assert-deep-strict-equal

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

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

1.2.0

3 months ago

1.1.2

4 months ago

1.1.1

6 months ago

1.1.0

10 months ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.4

2 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago