Jest is an amazing test runner and has some awesome assertion APIs built in by default. However I was not able to find a simple solution for testing deep equality while ignoring order. Even (jest-extended)[https://github.com/jest-community/jest-extended] did not have an easy solution.
This simple jest extension to test deep equality while ignoring order of object properties and array elements This now also checks contained string similarity by ignoring case, spaces and line breaks.
With npm:
npm install --save-dev jest-similar
With yarn:
yarn add -D jest-similar
Add jest-similar
to your Jest setupFilesAfterEnv
configuration. See for help
"jest": {
"setupFilesAfterEnv": ["jest-similar"]
}
"jest": {
"setupTestFrameworkScriptFile": "jest-similar"
}
If you are already using another test framework, like jest-chain, then you should create a test setup file and require
each of the frameworks you are using.
For example:
// ./testSetup.js
require('jest-similar');
Then in your Jest config:
"jest": {
"setupTestFrameworkScriptFile": "./testSetup.js"
}
If your editor does not recognise the custom jest-similar
matchers, add a global.d.ts
file to your project with:
import 'jest-similar';
For usage see test.js
- given string from files figure out common areas jumbled up