assert.deepStrictEqual for JSON object.
npm install assert-json-equalassert.deepStrictEqual for JSON object.
assert-json-equal provide a assertJsonEqual function.
assert.deepStrictEqual discriminate undefined value and missing property.
``js`
const a = {};
const b = {
undef: undefined
};
assert.throws(() => {
assert.deepStrictEqual(a, b); // => throw
});
assertJsonEqual does not discriminate undefined value and missing property.
It is useful for comparing JSON objects.
`js`
import { assertJsonEqual } from "assert-json-equal"
const a = {};
const b = {
undef: undefined
};
assertJsonEqual(a, b); // => pass
Install with npm:
npm install assert-json-equal
`tsassert.deepStrictEqual
/**
* for JSON object.assert.deepStrictEqual(a, b, [message])
* Same API with `
*/
export declare const assertJsonEqual: (actual: any, expected: any, message?: string | Error | undefined) => void;
Serialize and Deserialize object with JSON before compare objects with assert.deepStrictEqual.
`ts
import assert from "assert";
const normalizeJSON =
return JSON.parse(JSON.stringify(json));
};
/**
* assert.deepStrictEqual for JSON object.assert.deepStrictEqual(a, b, [message])
* Same API with `
* @param actual
* @param expected
* @param message
*/
export const assertJsonEqual = (actual: any, expected: any, message?: string | Error) => {
assert.deepStrictEqual(normalizeJSON(actual), normalizeJSON(expected), message);
}
See Releases page.
Install devDependencies and Run npm test:
npm test
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
1. Fork it!
2. Create your feature branch: git checkout -b my-new-featuregit commit -am 'Add some feature'
3. Commit your changes: git push origin my-new-feature`
4. Push to the branch:
5. Submit a pull request :D
MIT © azu