Make jest expect more convenient.
This should only be installed as a development dependency (devDependencies
) as it is only designed for testing.
npm i --save-dev jest-expect
Add jest-extended to your Jest setupTestFrameworkScriptFile configuration. See for help
{
"jest": {
"setupTestFrameworkScriptFile": "jest-expect"
}
}
-
All api of jest-extended.
-
Additional Jest matchers of
jest-expect
. -
To be continue...
Use toBeApproximate
to checkout if a value is approximately equal to a Number
.
test('toBeApproximate', () => {
expect(Math.PI).toBeApproximate(3);
expect(Math.PI).toBeApproximate(3.14);
expect(Math.PI).toBeApproximate(3.1416);
expect(Math.PI).not.toBeApproximate(4);
expect(Math.PI).not.toBeApproximate(3.15);
expect(Math.PI).not.toBeApproximate(3.1415);
});
MIT@hustcc.