Jest is a test runner from Facebook for client-side JavaScript applications and React applications specifically.
Jest ships with jsdom for DOM manipulation testing.
let oneObj = {name: 'nico', id: 2};
expect(oneObj).toEqual({name: 'nico'}) // false, should be exactly equal all Obj keys and values
expect(oneObj).toMatchObject({name: 'nico'}) // true
The assertion library is jasmine
test('Crawler Base Url Test', async () => {
expect(() => {myFunction()}).toThrow(Error);
})
Jest will look for test files with any of the following popular naming conventions:
The .test.js / .spec.js files (or the __tests__ folders) can be located at any depth under the src top level folder.
It's recommended to collocate the test file with the source file (ie put the test files (or __tests__ folders) next to the code they are testing ) because of:
test is a global variable injected by Jest. You need to run your tests through jest
test('3 equal 3', () => {
expect(3).toBe(3);
});
jest my-test --notify --config=config.json
experimental
- https://github.com/kvendrik/jest-lite
<script src="https://unpkg.com/[email protected]/dist/core.js"></script>
expect = jestLite.core.expect;
try {
expect(3).toBe(2)
} catch (e) {
// If the test is not good an exception is fired.
console.log(e.message);
}