Skip to content

Commit

Permalink
Add spy matchers tests using ES6 Map and Set
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp-spiess committed May 26, 2017
1 parent 8b79691 commit da50ded
Show file tree
Hide file tree
Showing 2 changed files with 226 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,38 @@ Expected mock function to not have been last called with:
<green>[Immutable.Map {a: {\\"b\\": \\"c\\"}}, Immutable.Map {a: {\\"b\\": \\"c\\"}}]</>"
`;

exports[`lastCalledWith works with jest.fn and Map 1`] = `
"<dim>expect(<red>jest.fn()</><dim>).not.lastCalledWith(<green>expected</><dim>)

Expected mock function to not have been last called with:
<green>[Map {1 => 2, 2 => 1}]</>"
`;

exports[`lastCalledWith works with jest.fn and Map 2`] = `
"<dim>expect(<red>jest.fn()</><dim>).lastCalledWith(<green>expected</><dim>)

Expected mock function to have been last called with:
<green>[Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}]</>
But it was last called with:
<red>[Map {1 => 2, 2 => 1}]</>"
`;

exports[`lastCalledWith works with jest.fn and Set 1`] = `
"<dim>expect(<red>jest.fn()</><dim>).not.lastCalledWith(<green>expected</><dim>)

Expected mock function to not have been last called with:
<green>[Set {1, 2}]</>"
`;

exports[`lastCalledWith works with jest.fn and Set 2`] = `
"<dim>expect(<red>jest.fn()</><dim>).lastCalledWith(<green>expected</><dim>)

Expected mock function to have been last called with:
<green>[Set {3, 4}]</>
But it was last called with:
<red>[Set {1, 2}]</>"
`;

exports[`lastCalledWith works with jest.fn and arguments that don't match 1`] = `
"<dim>expect(<red>jest.fn()</><dim>).lastCalledWith(<green>expected</><dim>)

Expand Down Expand Up @@ -121,6 +153,38 @@ Expected mock function not to have been called with:
<green>[Immutable.Map {a: {\\"b\\": \\"c\\"}}, Immutable.Map {a: {\\"b\\": \\"c\\"}}]</>"
`;

exports[`toBeCalledWith works with jest.fn and Map 1`] = `
"<dim>expect(<red>jest.fn()</><dim>).not.toBeCalledWith(<green>expected</><dim>)

Expected mock function not to have been called with:
<green>[Map {1 => 2, 2 => 1}]</>"
`;

exports[`toBeCalledWith works with jest.fn and Map 2`] = `
"<dim>expect(<red>jest.fn()</><dim>).toBeCalledWith(<green>expected</><dim>)

Expected mock function to have been called with:
<green>[Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}]</>
But it was called with:
<red>[Map {1 => 2, 2 => 1}]</>"
`;

exports[`toBeCalledWith works with jest.fn and Set 1`] = `
"<dim>expect(<red>jest.fn()</><dim>).not.toBeCalledWith(<green>expected</><dim>)

Expected mock function not to have been called with:
<green>[Set {1, 2}]</>"
`;

exports[`toBeCalledWith works with jest.fn and Set 2`] = `
"<dim>expect(<red>jest.fn()</><dim>).toBeCalledWith(<green>expected</><dim>)

Expected mock function to have been called with:
<green>[Set {3, 4}]</>
But it was called with:
<red>[Set {1, 2}]</>"
`;

exports[`toBeCalledWith works with jest.fn and arguments that don't match 1`] = `
"<dim>expect(<red>jest.fn()</><dim>).toBeCalledWith(<green>expected</><dim>)

Expand Down Expand Up @@ -300,6 +364,38 @@ Expected spy not to have been called with:
<green>[Immutable.Map {a: {\\"b\\": \\"c\\"}}, Immutable.Map {a: {\\"b\\": \\"c\\"}}]</>"
`;

exports[`toHaveBeenCalledWith works with jasmine.createSpy and Map 1`] = `
"<dim>expect(<red>spy</><dim>).not.toHaveBeenCalledWith(<green>expected</><dim>)

Expected spy not to have been called with:
<green>[Map {1 => 2, 2 => 1}]</>"
`;

exports[`toHaveBeenCalledWith works with jasmine.createSpy and Map 2`] = `
"<dim>expect(<red>spy</><dim>).toHaveBeenCalledWith(<green>expected</><dim>)

Expected spy to have been called with:
<green>[Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}]</>
But it was called with:
<red>[Map {1 => 2, 2 => 1}]</>"
`;

exports[`toHaveBeenCalledWith works with jasmine.createSpy and Set 1`] = `
"<dim>expect(<red>spy</><dim>).not.toHaveBeenCalledWith(<green>expected</><dim>)

Expected spy not to have been called with:
<green>[Set {1, 2}]</>"
`;

exports[`toHaveBeenCalledWith works with jasmine.createSpy and Set 2`] = `
"<dim>expect(<red>spy</><dim>).toHaveBeenCalledWith(<green>expected</><dim>)

Expected spy to have been called with:
<green>[Set {3, 4}]</>
But it was called with:
<red>[Set {1, 2}]</>"
`;

exports[`toHaveBeenCalledWith works with jasmine.createSpy and arguments that don't match 1`] = `
"<dim>expect(<red>spy</><dim>).toHaveBeenCalledWith(<green>expected</><dim>)

Expand Down Expand Up @@ -347,6 +443,38 @@ Expected mock function not to have been called with:
<green>[Immutable.Map {a: {\\"b\\": \\"c\\"}}, Immutable.Map {a: {\\"b\\": \\"c\\"}}]</>"
`;

exports[`toHaveBeenCalledWith works with jest.fn and Map 1`] = `
"<dim>expect(<red>jest.fn()</><dim>).not.toHaveBeenCalledWith(<green>expected</><dim>)

Expected mock function not to have been called with:
<green>[Map {1 => 2, 2 => 1}]</>"
`;

exports[`toHaveBeenCalledWith works with jest.fn and Map 2`] = `
"<dim>expect(<red>jest.fn()</><dim>).toHaveBeenCalledWith(<green>expected</><dim>)

Expected mock function to have been called with:
<green>[Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}]</>
But it was called with:
<red>[Map {1 => 2, 2 => 1}]</>"
`;

exports[`toHaveBeenCalledWith works with jest.fn and Set 1`] = `
"<dim>expect(<red>jest.fn()</><dim>).not.toHaveBeenCalledWith(<green>expected</><dim>)

Expected mock function not to have been called with:
<green>[Set {1, 2}]</>"
`;

exports[`toHaveBeenCalledWith works with jest.fn and Set 2`] = `
"<dim>expect(<red>jest.fn()</><dim>).toHaveBeenCalledWith(<green>expected</><dim>)

Expected mock function to have been called with:
<green>[Set {3, 4}]</>
But it was called with:
<red>[Set {1, 2}]</>"
`;

exports[`toHaveBeenCalledWith works with jest.fn and arguments that don't match 1`] = `
"<dim>expect(<red>jest.fn()</><dim>).toHaveBeenCalledWith(<green>expected</><dim>)

Expand Down Expand Up @@ -402,6 +530,38 @@ Expected spy to not have been last called with:
<green>[Immutable.Map {a: {\\"b\\": \\"c\\"}}, Immutable.Map {a: {\\"b\\": \\"c\\"}}]</>"
`;

exports[`toHaveBeenLastCalledWith works with jasmine.createSpy and Map 1`] = `
"<dim>expect(<red>spy</><dim>).not.toHaveBeenLastCalledWith(<green>expected</><dim>)

Expected spy to not have been last called with:
<green>[Map {1 => 2, 2 => 1}]</>"
`;

exports[`toHaveBeenLastCalledWith works with jasmine.createSpy and Map 2`] = `
"<dim>expect(<red>spy</><dim>).toHaveBeenLastCalledWith(<green>expected</><dim>)

Expected spy to have been last called with:
<green>[Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}]</>
But it was last called with:
<red>[Map {1 => 2, 2 => 1}]</>"
`;

exports[`toHaveBeenLastCalledWith works with jasmine.createSpy and Set 1`] = `
"<dim>expect(<red>spy</><dim>).not.toHaveBeenLastCalledWith(<green>expected</><dim>)

Expected spy to not have been last called with:
<green>[Set {1, 2}]</>"
`;

exports[`toHaveBeenLastCalledWith works with jasmine.createSpy and Set 2`] = `
"<dim>expect(<red>spy</><dim>).toHaveBeenLastCalledWith(<green>expected</><dim>)

Expected spy to have been last called with:
<green>[Set {3, 4}]</>
But it was last called with:
<red>[Set {1, 2}]</>"
`;

exports[`toHaveBeenLastCalledWith works with jasmine.createSpy and arguments that don't match 1`] = `
"<dim>expect(<red>spy</><dim>).toHaveBeenLastCalledWith(<green>expected</><dim>)

Expand Down Expand Up @@ -450,6 +610,38 @@ Expected mock function to not have been last called with:
<green>[Immutable.Map {a: {\\"b\\": \\"c\\"}}, Immutable.Map {a: {\\"b\\": \\"c\\"}}]</>"
`;

exports[`toHaveBeenLastCalledWith works with jest.fn and Map 1`] = `
"<dim>expect(<red>jest.fn()</><dim>).not.toHaveBeenLastCalledWith(<green>expected</><dim>)

Expected mock function to not have been last called with:
<green>[Map {1 => 2, 2 => 1}]</>"
`;

exports[`toHaveBeenLastCalledWith works with jest.fn and Map 2`] = `
"<dim>expect(<red>jest.fn()</><dim>).toHaveBeenLastCalledWith(<green>expected</><dim>)

Expected mock function to have been last called with:
<green>[Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}]</>
But it was last called with:
<red>[Map {1 => 2, 2 => 1}]</>"
`;

exports[`toHaveBeenLastCalledWith works with jest.fn and Set 1`] = `
"<dim>expect(<red>jest.fn()</><dim>).not.toHaveBeenLastCalledWith(<green>expected</><dim>)

Expected mock function to not have been last called with:
<green>[Set {1, 2}]</>"
`;

exports[`toHaveBeenLastCalledWith works with jest.fn and Set 2`] = `
"<dim>expect(<red>jest.fn()</><dim>).toHaveBeenLastCalledWith(<green>expected</><dim>)

Expected mock function to have been last called with:
<green>[Set {3, 4}]</>
But it was last called with:
<red>[Set {1, 2}]</>"
`;

exports[`toHaveBeenLastCalledWith works with jest.fn and arguments that don't match 1`] = `
"<dim>expect(<red>jest.fn()</><dim>).toHaveBeenLastCalledWith(<green>expected</><dim>)

Expand Down
34 changes: 34 additions & 0 deletions packages/jest-matchers/src/__tests__/spyMatchers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,40 @@ describe('toHaveBeenCalledTimes', () => {
).toThrowErrorMatchingSnapshot();
});

test(`${calledWith} works with ${mockName} and Map`, () => {
const fn = getFunction();

const m1 = new Map([[1, 2], [2, 1]]);
const m2 = new Map([[1, 2], [2, 1]]);
const m3 = new Map([['a', 'b'], ['b', 'a']]);

fn(m1);

jestExpect(fn)[calledWith](m2);
jestExpect(fn).not[calledWith](m3);
expect(() =>
jestExpect(fn).not[calledWith](m2),
).toThrowErrorMatchingSnapshot();
expect(() => jestExpect(fn)[calledWith](m3)).toThrowErrorMatchingSnapshot();
});

test(`${calledWith} works with ${mockName} and Set`, () => {
const fn = getFunction();

const s1 = new Set([1, 2]);
const s2 = new Set([1, 2]);
const s3 = new Set([3, 4]);

fn(s1);

jestExpect(fn)[calledWith](s2);
jestExpect(fn).not[calledWith](s3);
expect(() =>
jestExpect(fn).not[calledWith](s2),
).toThrowErrorMatchingSnapshot();
expect(() => jestExpect(fn)[calledWith](s3)).toThrowErrorMatchingSnapshot();
});

test(`${calledWith} works with ${mockName} and Immutable.js objects`, () => {
const fn = getFunction();
const directlyCreated = new Immutable.Map([['a', {b: 'c'}]]);
Expand Down

0 comments on commit da50ded

Please sign in to comment.