-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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(tests): clean up jest.Mock
usage in tests
#13238
Conversation
@@ -652,7 +658,7 @@ const createSpy = (fn: jest.Mock) => { | |||
|
|||
test('incomplete recursive calls are handled properly', () => { | |||
// sums up all integers from 0 -> value, using recursion | |||
const fn: jest.Mock = jest.fn(value => { | |||
const fn: jest.Mock<number, [value: number]> = jest.fn(value => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise the default is jest.Mock<any, any>
.
const cases: Record<string, jest.Mock> = { | ||
fancyCondition: jest.fn(path => path.length > 10), | ||
testRegex: jest.fn(path => /.test.js$/.test(path)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jest.fn()
does nothing here. Can be simplified.
afterEach(() => { | ||
jest.clearAllMocks(); | ||
jest.resetModules(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tricky one. If I got it right: fake
was being reset manually, looks like jest.clearAllMocks()
does the same job; also require
in beforeEach
above has no effect without jest.resetModules()
because of module caching. Or?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! 👍
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Following up #13235
Summary
Cleaning up
jest.Mock
usage in tests. The type was unnecessary or used to manually reset a mock function (jest.clearAllMocks()
seemed like better idea). Otherwise I used generic type arguments to have it typed it properly. Also fixed other type errors in these tests and a couple of typos caught by cspell.This should help migrating to build-in Jest types and to setup typecheck for test files one day.
Test plan
Green CI.