Skip to content

Commit 07ef0ca

Browse files
Add spy matchers tests using ES6 Map and Set
1 parent 303cb8e commit 07ef0ca

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

packages/jest-matchers/src/__tests__/__snapshots__/spyMatchers-test.js.snap

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,38 @@ Expected mock function to not have been last called with:
2323
<green>[Immutable.Map {a: {\\"b\\": \\"c\\"}}, Immutable.Map {a: {\\"b\\": \\"c\\"}}]</>"
2424
`;
2525

26+
exports[`lastCalledWith works with Map 1`] = `
27+
"<dim>expect(<red>jest.fn()</><dim>).not.lastCalledWith(<green>expected</><dim>)
28+
29+
Expected mock function to not have been last called with:
30+
<green>[Map {1 => 2, 2 => 1}]</>"
31+
`;
32+
33+
exports[`lastCalledWith works with Map 2`] = `
34+
"<dim>expect(<red>jest.fn()</><dim>).lastCalledWith(<green>expected</><dim>)
35+
36+
Expected mock function to have been last called with:
37+
<green>[Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}]</>
38+
But it was last called with:
39+
<red>[Map {1 => 2, 2 => 1}]</>"
40+
`;
41+
42+
exports[`lastCalledWith works with Set 1`] = `
43+
"<dim>expect(<red>jest.fn()</><dim>).not.lastCalledWith(<green>expected</><dim>)
44+
45+
Expected mock function to not have been last called with:
46+
<green>[Set {1, 2}]</>"
47+
`;
48+
49+
exports[`lastCalledWith works with Set 2`] = `
50+
"<dim>expect(<red>jest.fn()</><dim>).lastCalledWith(<green>expected</><dim>)
51+
52+
Expected mock function to have been last called with:
53+
<green>[Set {3, 4}]</>
54+
But it was last called with:
55+
<red>[Set {1, 2}]</>"
56+
`;
57+
2658
exports[`lastCalledWith works with arguments that don't match 1`] = `
2759
"<dim>expect(<red>jest.fn()</><dim>).lastCalledWith(<green>expected</><dim>)
2860

@@ -219,6 +251,38 @@ Expected mock function not to have been called with:
219251
<green>[Immutable.Map {a: {\\"b\\": \\"c\\"}}, Immutable.Map {a: {\\"b\\": \\"c\\"}}]</>"
220252
`;
221253

254+
exports[`toHaveBeenCalledWith works with Map 1`] = `
255+
"<dim>expect(<red>jest.fn()</><dim>).not.toHaveBeenCalledWith(<green>expected</><dim>)
256+
257+
Expected mock function not to have been called with:
258+
<green>[Map {1 => 2, 2 => 1}]</>"
259+
`;
260+
261+
exports[`toHaveBeenCalledWith works with Map 2`] = `
262+
"<dim>expect(<red>jest.fn()</><dim>).toHaveBeenCalledWith(<green>expected</><dim>)
263+
264+
Expected mock function to have been called with:
265+
<green>[Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}]</>
266+
But it was called with:
267+
<red>[Map {1 => 2, 2 => 1}]</>"
268+
`;
269+
270+
exports[`toHaveBeenCalledWith works with Set 1`] = `
271+
"<dim>expect(<red>jest.fn()</><dim>).not.toHaveBeenCalledWith(<green>expected</><dim>)
272+
273+
Expected mock function not to have been called with:
274+
<green>[Set {1, 2}]</>"
275+
`;
276+
277+
exports[`toHaveBeenCalledWith works with Set 2`] = `
278+
"<dim>expect(<red>jest.fn()</><dim>).toHaveBeenCalledWith(<green>expected</><dim>)
279+
280+
Expected mock function to have been called with:
281+
<green>[Set {3, 4}]</>
282+
But it was called with:
283+
<red>[Set {1, 2}]</>"
284+
`;
285+
222286
exports[`toHaveBeenCalledWith works with arguments that don't match 1`] = `
223287
"<dim>expect(<red>jest.fn()</><dim>).toHaveBeenCalledWith(<green>expected</><dim>)
224288

@@ -274,6 +338,38 @@ Expected mock function to not have been last called with:
274338
<green>[Immutable.Map {a: {\\"b\\": \\"c\\"}}, Immutable.Map {a: {\\"b\\": \\"c\\"}}]</>"
275339
`;
276340

341+
exports[`toHaveBeenLastCalledWith works with Map 1`] = `
342+
"<dim>expect(<red>jest.fn()</><dim>).not.toHaveBeenLastCalledWith(<green>expected</><dim>)
343+
344+
Expected mock function to not have been last called with:
345+
<green>[Map {1 => 2, 2 => 1}]</>"
346+
`;
347+
348+
exports[`toHaveBeenLastCalledWith works with Map 2`] = `
349+
"<dim>expect(<red>jest.fn()</><dim>).toHaveBeenLastCalledWith(<green>expected</><dim>)
350+
351+
Expected mock function to have been last called with:
352+
<green>[Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}]</>
353+
But it was last called with:
354+
<red>[Map {1 => 2, 2 => 1}]</>"
355+
`;
356+
357+
exports[`toHaveBeenLastCalledWith works with Set 1`] = `
358+
"<dim>expect(<red>jest.fn()</><dim>).not.toHaveBeenLastCalledWith(<green>expected</><dim>)
359+
360+
Expected mock function to not have been last called with:
361+
<green>[Set {1, 2}]</>"
362+
`;
363+
364+
exports[`toHaveBeenLastCalledWith works with Set 2`] = `
365+
"<dim>expect(<red>jest.fn()</><dim>).toHaveBeenLastCalledWith(<green>expected</><dim>)
366+
367+
Expected mock function to have been last called with:
368+
<green>[Set {3, 4}]</>
369+
But it was last called with:
370+
<red>[Set {1, 2}]</>"
371+
`;
372+
277373
exports[`toHaveBeenLastCalledWith works with arguments that don't match 1`] = `
278374
"<dim>expect(<red>jest.fn()</><dim>).toHaveBeenLastCalledWith(<green>expected</><dim>)
279375

packages/jest-matchers/src/__tests__/spyMatchers-test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,42 @@ describe('toHaveBeenCalledTimes', () => {
169169
).toThrowErrorMatchingSnapshot();
170170
});
171171

172+
test(`${calledWith} works with Map`, () => {
173+
const fn = jest.fn();
174+
175+
const m1 = new Map([[1, 2], [2, 1]]);
176+
const m2 = new Map([[1, 2], [2, 1]]);
177+
const m3 = new Map([['a', 'b'], ['b', 'a']]);
178+
179+
fn(m1);
180+
181+
jestExpect(fn)[calledWith](m2);
182+
jestExpect(fn).not[calledWith](m3);
183+
184+
expect(() =>
185+
jestExpect(fn).not[calledWith](m2),
186+
).toThrowErrorMatchingSnapshot();
187+
expect(() => jestExpect(fn)[calledWith](m3)).toThrowErrorMatchingSnapshot();
188+
});
189+
190+
test(`${calledWith} works with Set`, () => {
191+
const fn = jest.fn();
192+
193+
const s1 = new Set([1, 2]);
194+
const s2 = new Set([1, 2]);
195+
const s3 = new Set([3, 4]);
196+
197+
fn(s1);
198+
199+
jestExpect(fn)[calledWith](s2);
200+
jestExpect(fn).not[calledWith](s3);
201+
202+
expect(() =>
203+
jestExpect(fn).not[calledWith](s2),
204+
).toThrowErrorMatchingSnapshot();
205+
expect(() => jestExpect(fn)[calledWith](s3)).toThrowErrorMatchingSnapshot();
206+
});
207+
172208
test(`${calledWith} works with Immutable.js objects`, () => {
173209
const fn = jest.fn();
174210
const directlyCreated = new Immutable.Map([['a', {b: 'c'}]]);

0 commit comments

Comments
 (0)