jest-similar
v1.0.8
Published
this provides a matcher for recursive deep equality but ignoring order in arrays and object keys
Downloads
5
Readme
Problem
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.
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.
Installation
With npm:
npm install --save-dev jest-similar
With yarn:
yarn add -D jest-similar
Setup
Jest >v24
Add jest-similar
to your Jest setupFilesAfterEnv
configuration. See for help
"jest": {
"setupFilesAfterEnv": ["jest-similar"]
}
Jest <v23
"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"
}
Typescript
If your editor does not recognise the custom jest-similar
matchers, add a global.d.ts
file to your project with:
import 'jest-similar';
API
.toBeSimilar()
For usage see test.js
LICENSE
Todos
- given string from files figure out common areas jumbled up