Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add matcher result tests #2572

Merged
merged 4 commits into from
Jan 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/jest-matchers/src/__tests__/matchers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ describe('.toBe()', () => {
expect(() => jestExpect(obj).toBe({}))
.toThrowErrorMatchingSnapshot();
});

test('assertion error matcherResult property contains matcher name, expected and actual values', () => {
const actual = {a: 1};
const expected = {a: 2};
try {
jestExpect(actual).toBe(expected);
} catch (error) {
expect(error.matcherResult).toEqual(expect.objectContaining({
actual,
expected,
name: 'toBe',
}));
}
});
});

describe('.toEqual()', () => {
Expand Down Expand Up @@ -101,6 +115,20 @@ describe('.toEqual()', () => {
.toThrowErrorMatchingSnapshot();
});
});

test('assertion error matcherResult property contains matcher name, expected and actual values', () => {
const actual = {a: 1};
const expected = {a: 2};
try {
jestExpect(actual).toEqual(expected);
} catch (error) {
expect(error.matcherResult).toEqual(expect.objectContaining({
actual,
expected,
name: 'toEqual',
}));
}
});
});

describe('.toBeInstanceOf()', () => {
Expand Down
27 changes: 27 additions & 0 deletions packages/jest-snapshot/src/__tests__/matcher-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';

const {toMatchSnapshot} = require('../');

it(`matcher returns matcher name, expected and actual values`, () => {
const actual = 'a';
const expected = 'b';
const matcher = toMatchSnapshot.bind({
snapshotState: {match: (testName, received) => ({actual, expected})},
});

const matcherResult = matcher({a: 1});

expect(matcherResult).toEqual(expect.objectContaining({
actual,
expected,
name: 'toMatchSnapshot',
}));
});