Repository: https://repl.it/repls/PleasedSubmissiveAfricanbushviper
function doWork() {
const dispatch = jest.fn();
dispatch(null);
dispatch({});
dispatch('blah');
dispatch(() => {});
return dispatch;
}
test('passes with exact string', () => {
const dispatch = doWork();
expect(dispatch).toBeCalledWith('blah');
});
test('fails with matcher', () => {
const dispatch = doWork();
expect(dispatch).toBeCalledWith(expect.stringContaining('bla'));
});
Output:
FAIL ./add-test.js
● fails with matcher
TypeError: Cannot read property 'includes' of null
at Object.<anonymous>.test (add-test.js:17:20)
at Promise (<anonymous>)
at Promise.resolve.then.el (../../usr/local/share/.config/yarn/global/node_modules/p-map/index.js:42:16)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:169:7)
✓ passes with exact string (6ms)
✕ fails with matcher (2ms)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 passed, 2 total
Jest should skip the values which don't match and only fail if none match. In my example, the second test should pass because expect.stringMatching('bla') passes on the third call with 'blah'. Basically, the same behaviour as asserting with an exact value.
Tested with
Jest v20.0.4 node v7.4.0 linux/amd64 (repl.it)
Jest v21.2.1 node v8.9.1 macOS X 10.13.1 (locally)
Repository: https://repl.it/repls/PleasedSubmissiveAfricanbushviper
Output:
Jest should skip the values which don't match and only fail if none match. In my example, the second test should pass because
expect.stringMatching('bla')passes on the third call with'blah'. Basically, the same behaviour as asserting with an exact value.Tested with
Jest v20.0.4 node v7.4.0 linux/amd64 (repl.it)
Jest v21.2.1 node v8.9.1 macOS X 10.13.1 (locally)