Skip to content

Commit

Permalink
Support varargs in toHaveBeenCalledOnceWith (closes #517)
Browse files Browse the repository at this point in the history
  • Loading branch information
keeganwitt committed Jan 31, 2023
1 parent 6fbb99e commit 5918fe9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions test/matchers/toHaveBeenCalledOnceWith.test.js
Expand Up @@ -13,6 +13,16 @@ describe('.toHaveBeenCalledOnceWith', () => {
expect(mock).toHaveBeenCalledOnceWith('hello');
});

test('passes if mock was invoked exactly once with the expected values in an array', () => {
mock(['hello', 'there']);
expect(mock).toHaveBeenCalledOnceWith(['hello', 'there']);
});

test('passes if mock was invoked exactly once with the expected values', () => {
mock('hello', 'there');
expect(mock).toHaveBeenCalledOnceWith('hello', 'there');
});

test('fails if mock was never invoked indicating that it was invoked 0 times', () => {
expect(() => expect(mock).toHaveBeenCalledOnceWith('hello')).toThrowErrorMatchingSnapshot();
});
Expand Down Expand Up @@ -59,4 +69,14 @@ describe('.not.toHaveBeenCalledOnceWith', () => {
mock('not hello');
expect(mock).not.toHaveBeenCalledOnceWith('hello');
});

test('passes if mock was invoked exactly once without both expected values in an array', () => {
mock(['hello', 'there']);
expect(mock).not.toHaveBeenCalledOnceWith(['hello', 'not there']);
});

test('passes if mock was invoked exactly once without both expected values', () => {
mock('hello', 'there');
expect(mock).not.toHaveBeenCalledOnceWith('hello', 'not there');
});
});
2 changes: 1 addition & 1 deletion website/docs/matchers/Mock.mdx
Expand Up @@ -50,7 +50,7 @@ Use `.toHaveBeenCalledOnce` to check if a `Mock` was called exactly one time.

### .toHaveBeenCalledOnceWith()

Use `.toHaveBeenCalledOnceWith` to check if a `Mock` was called exactly one time with the expected value.
Use `.toHaveBeenCalledOnceWith` to check if a `Mock` was called exactly one time with the expected values.

<TestFile name="toHaveBeenCalledOnceWith">
{`test('passes only if mock was called exactly once with the expected value', () => {
Expand Down

0 comments on commit 5918fe9

Please sign in to comment.