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

Remove aliased matchers #13192

Closed
Closed
Prev Previous commit
Next Next commit
chore: remove .nthCalledWith() matcher
  • Loading branch information
EduardoSCosta committed Aug 30, 2022
commit c46b16cceb2ef7ab2002189858913be8091f870f
225 changes: 0 additions & 225 deletions packages/expect/src/__tests__/__snapshots__/spyMatchers.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -143,231 +143,6 @@ Expected: not <g>undefined</>
Number of returns: <r>1</>
`;

exports[`nthCalledWith includes the custom mock name in the error message 1`] = `
<d>expect(</><r>named-mock</><d>).</>not<d>.</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: not <g>"foo"</>, <g>"bar"</>

Number of calls: <r>1</>
`;

exports[`nthCalledWith negative throw matcher error for n that is not integer 1`] = `
<d>expect(</><r>received</><d>).</>not<d>.</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

<b>Matcher error</>: n must be a positive integer

n has type: number
n has value: Infinity
`;

exports[`nthCalledWith positive throw matcher error for n that is not integer 1`] = `
<d>expect(</><r>received</><d>).</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

<b>Matcher error</>: n must be a positive integer

n has type: number
n has value: 0.1
`;

exports[`nthCalledWith positive throw matcher error for n that is not positive integer 1`] = `
<d>expect(</><r>received</><d>).</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

<b>Matcher error</>: n must be a positive integer

n has type: number
n has value: 0
`;

exports[`nthCalledWith works only on spies or jest.fn 1`] = `
<d>expect(</><r>received</><d>).</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

<b>Matcher error</>: <r>received</> value must be a mock or spy function

Received has type: function
Received has value: <r>[Function fn]</>
`;

exports[`nthCalledWith works when not called 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: <g>"foo"</>, <g>"bar"</>

Number of calls: <r>0</>
`;

exports[`nthCalledWith works with Immutable.js objects 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: not <g>Immutable.Map {"a": {"b": "c"}}</>, <g>Immutable.Map {"a": {"b": "c"}}</>

Number of calls: <r>1</>
`;

exports[`nthCalledWith works with Map 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: not <g>Map {1 => 2, 2 => 1}</>

Number of calls: <r>1</>
`;

exports[`nthCalledWith works with Map 2`] = `
<d>expect(</><r>jest.fn()</><d>).</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
<g>- Expected</>
<r>+ Received</>

<d> Map {</>
<g>- "a" => "b",</>
<g>- "b" => "a",</>
<r>+ 1 => 2,</>
<r>+ 2 => 1,</>
<d> }</>,

Number of calls: <r>1</>
`;

exports[`nthCalledWith works with Set 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: not <g>Set {1, 2}</>

Number of calls: <r>1</>
`;

exports[`nthCalledWith works with Set 2`] = `
<d>expect(</><r>jest.fn()</><d>).</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
<g>- Expected</>
<r>+ Received</>

<d> Set {</>
<g>- 3,</>
<g>- 4,</>
<r>+ 1,</>
<r>+ 2,</>
<d> }</>,

Number of calls: <r>1</>
`;

exports[`nthCalledWith works with arguments that don't match 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: <g>"foo"</>, <g>"bar"</>
Received: <d>"foo"</>, <r>"bar1"</>

Number of calls: <r>1</>
`;

exports[`nthCalledWith works with arguments that don't match in number of arguments 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: <g>"foo"</>, <g>"bar"</>
Received: <d>"foo"</>, <d>"bar"</>, <r>"plop"</>

Number of calls: <r>1</>
`;

exports[`nthCalledWith works with arguments that don't match in size even if one is an optional matcher 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: <g>"foo"</>, <g>optionalFn<></>
Received: <d>"foo"</>

Number of calls: <r>1</>
`;

exports[`nthCalledWith works with arguments that don't match with matchers 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: <g>Any<String></>, <g>Any<Number></>
Received: <d>"foo"</>, <r>"bar"</>

Number of calls: <r>1</>
`;

exports[`nthCalledWith works with arguments that don't match with matchers even when argument is undefined 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: <g>"foo"</>, <g>Any<String></>
Received: <d>"foo"</>, <r>undefined</>

Number of calls: <r>1</>
`;

exports[`nthCalledWith works with arguments that match 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: not <g>"foo"</>, <g>"bar"</>

Number of calls: <r>1</>
`;

exports[`nthCalledWith works with arguments that match with matchers 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: not <g>Any<String></>, <g>Any<String></>
Received: <r>0</>, <r>["foo", "bar"]</>

Number of calls: <r>1</>
`;

exports[`nthCalledWith works with three calls 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: not <g>"foo1"</>, <g>"bar"</>
Received
-> 1: <d>"foo1"</>, <d>"bar"</>
2: <r>"foo"</>, <r>"bar1"</>

Number of calls: <r>3</>
`;

exports[`nthCalledWith works with trailing undefined arguments 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: <g>"foo"</>
Received: <d>"foo"</>, <r>undefined</>

Number of calls: <r>1</>
`;

exports[`nthCalledWith works with trailing undefined arguments if requested by the match query 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: not <g>"foo"</>, <g>undefined</>

Number of calls: <r>1</>
`;

exports[`nthCalledWith works with trailing undefined arguments when explicitely requested as optional by matcher 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>nthCalledWith<d>(</>n<d>, </><g>...expected</><d>)</>

n: 1
Expected: not <g>"foo"</>, <g>optionalFn<></>
Received: <r>0</>, <r>["foo", undefined]</>

Number of calls: <r>1</>
`;

exports[`nthReturnedWith a call that throws is not considered to have returned 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>nthReturnedWith<d>(</>n<d>, </><g>expected</><d>)</>

Expand Down
10 changes: 3 additions & 7 deletions packages/expect/src/__tests__/spyMatchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,20 @@ describe('toHaveBeenCalledTimes', () => {

[
'toHaveBeenLastCalledWith',
'nthCalledWith',
'toHaveBeenNthCalledWith',
'toHaveBeenCalledWith',
].forEach(calledWith => {
const caller = function (
callee: (...a: Array<unknown>) => void,
...args: Array<unknown>
) {
if (
calledWith === 'nthCalledWith' ||
calledWith === 'toHaveBeenNthCalledWith'
) {
if (calledWith === 'toHaveBeenNthCalledWith') {
callee(1, ...args);
} else {
callee(...args);
}
};

describe(`${calledWith}`, () => {
test('works only on spies or jest.fn', () => {
const fn = function fn() {};
Expand Down Expand Up @@ -465,8 +462,7 @@ describe('toHaveBeenCalledTimes', () => {
});
}

const nthCalled = ['toHaveBeenNthCalledWith', 'nthCalledWith'];
if (nthCalled.indexOf(calledWith) >= 0) {
if (calledWith === 'toHaveBeenNthCalledWith') {
test('works with three calls', () => {
const fn = jest.fn();
fn('foo1', 'bar');
Expand Down
1 change: 0 additions & 1 deletion packages/expect/src/spyMatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,6 @@ const createNthReturnedWithMatcher = (matcherName: string) =>

const spyMatchers: MatchersObject = {
lastReturnedWith: createLastReturnedMatcher('lastReturnedWith'),
nthCalledWith: createNthCalledWithMatcher('nthCalledWith'),
nthReturnedWith: createNthReturnedWithMatcher('nthReturnedWith'),
toHaveBeenCalled: createToBeCalledMatcher('toHaveBeenCalled'),
toHaveBeenCalledTimes: createToBeCalledTimesMatcher('toHaveBeenCalledTimes'),
Expand Down
4 changes: 0 additions & 4 deletions packages/expect/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ export interface Matchers<R extends void | Promise<void>> {
* Ensure that the last call to a mock function has returned a specified value.
*/
lastReturnedWith(expected: unknown): R;
/**
* Ensure that a mock function is called with specific arguments on an Nth call.
*/
nthCalledWith(nth: number, ...expected: Array<unknown>): R;
/**
* Ensure that the nth call to a mock function has returned a specified value.
*/
Expand Down
Loading