Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix: interoperability with @golevelup/ts-jest #89

Closed
mjgp2 opened this issue Nov 25, 2021 · 5 comments
Closed

Fix: interoperability with @golevelup/ts-jest #89

mjgp2 opened this issue Nov 25, 2021 · 5 comments

Comments

@mjgp2
Copy link
Contributor

mjgp2 commented Nov 25, 2021

Hi! 👋

I had a problem using createMock from @golevelup/ts-jest because it uses proxies to fake properties, and the test below against _isAllArgsFunctionMatcher gives a false positive (returns a jest.fn() instance).

Here is the diff that solved my problem:

diff --git a/node_modules/jest-when/src/when.js b/node_modules/jest-when/src/when.js
index 760b9bb..b7590bc 100644
--- a/node_modules/jest-when/src/when.js
+++ b/node_modules/jest-when/src/when.js
@@ -93,7 +93,7 @@ class WhenMock {
 
           let isMatch = false
 
-          if (matchers && matchers[0] && matchers[0]._isAllArgsFunctionMatcher) {
+          if (matchers && matchers[0] && (typeof matchers[0] === 'function' || typeof matchers[0] === 'object') && '_isAllArgsFunctionMatcher' in matchers[0] && matchers[0]._isAllArgsFunctionMatcher) {
             if (matchers.length > 1) throw new Error('When using when.allArgs, it must be the one and only matcher provided to calledWith. You have incorrectly provided other matchers along with when.allArgs.')
             isMatch = checkArgumentMatchers(expectCall, [args])(true, matchers[0], 0)
           } else {
@Djaler
Copy link

Djaler commented Dec 9, 2021

Same thing with jest-mock-extended. I think you should check more strictly, like matchers[0]._isAllArgsFunctionMatcher === true

@timkindberg
Copy link
Owner

Can someone make a PR with test for this pls?

@mjgp2
Copy link
Contributor Author

mjgp2 commented Dec 20, 2021

PR made: #93

timkindberg added a commit that referenced this issue Feb 7, 2022
@timkindberg
Copy link
Owner

Sorry for the delay... I didn't fully understand this one because I don't use either of these two libraries so I needed some extra time to review. It's in v3.5.1.

@mjgp2
Copy link
Contributor Author

mjgp2 commented Feb 8, 2022

Brilliant, thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants