From 5918fe9234b387608806a9522fd103135f98feac Mon Sep 17 00:00:00 2001 From: Keegan Witt Date: Mon, 28 Nov 2022 12:13:51 -0500 Subject: [PATCH] Support varargs in toHaveBeenCalledOnceWith (closes #517) --- .../matchers/toHaveBeenCalledOnceWith.test.js | 20 +++++++++++++++++++ website/docs/matchers/Mock.mdx | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/test/matchers/toHaveBeenCalledOnceWith.test.js b/test/matchers/toHaveBeenCalledOnceWith.test.js index 23c3ac4f..3e1e8741 100644 --- a/test/matchers/toHaveBeenCalledOnceWith.test.js +++ b/test/matchers/toHaveBeenCalledOnceWith.test.js @@ -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(); }); @@ -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'); + }); }); diff --git a/website/docs/matchers/Mock.mdx b/website/docs/matchers/Mock.mdx index 114b92ed..21803c67 100644 --- a/website/docs/matchers/Mock.mdx +++ b/website/docs/matchers/Mock.mdx @@ -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. {`test('passes only if mock was called exactly once with the expected value', () => {