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
Fix toHaveBeenCalledBefore/toHaveBeenCalledAfter type definition #292
Fix toHaveBeenCalledBefore/toHaveBeenCalledAfter type definition #292
Conversation
6ff252a
to
e92c9f5
Compare
This change allows `MockedFunction` to be used where `Mock` can be used. I don't think this fundamentally changes `MockedFunction`, just makes it more robust. This would resolve issues where an extended expect method takes a `Mock` type, but the mocking library uses `MockedFunction`. Related issues: extend-chrome/jest-chrome#9 jest-community/jest-extended#292
Until this gets merged, you can fix this in your own project by adding the following to a declaration file ( /// <reference types="jest" />
declare namespace jest {
interface Matchers {
/**
* Use `.toHaveBeenCalledBefore` when checking if a `MockInstance` was called before another `MockInstance`.
*
* Note: Required Jest version >=23
*
* @param {MockInstance} mock
*/
toHaveBeenCalledBefore(mock: jest.MockInstance): R
/**
* Use `.toHaveBeenCalledAfter` when checking if a `MockInstance` was called after another `MockInstance`.
*
* Note: Required Jest version >=23
*
* @param {MockInstance} mock
*/
toHaveBeenCalledAfter(mock: jest.MockInstance): R
}
interface Expect {
/**
* Use `.toHaveBeenCalledBefore` when checking if a `MockInstance` was called before another `MockInstance`.
*
* Note: Required Jest version >=23
*
* @param {MockInstance} mock
*/
toHaveBeenCalledBefore(mock: jest.MockInstance): R
/**
* Use `.toHaveBeenCalledAfter` when checking if a `MockInstance` was called after another `MockInstance`.
*
* Note: Required Jest version >=23
*
* @param {MockInstance} mock
*/
toHaveBeenCalledAfter(mock: jest.MockInstance): R
}
} |
e92c9f5
to
be4689c
Compare
Codecov Report
@@ Coverage Diff @@
## main #292 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 71 71
Lines 582 582
Branches 148 148
=========================================
Hits 582 582 Continue to review full report at Codecov.
|
be4689c
to
90ea4aa
Compare
What
I get a compiler error when passing a
jest.MockedFunction
type totoHaveBeenCalledAfter()/toHaveBeenCalledBefore()
.Why
Code showing the issue.
I get this compiler error.
Changing these to
jest.MockInstance
resolves the issue and should work for all use cases as bothjest.MockedFunction
andjest.MockedClass
extendjest.MockInstance
.Notes
Housekeeping