Skip to content
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

chore: migrate jest-mock type tests to TSTyche #14884

Merged
merged 5 commits into from
Feb 20, 2024
Merged

chore: migrate jest-mock type tests to TSTyche #14884

merged 5 commits into from
Feb 20, 2024

Conversation

mrazauskas
Copy link
Contributor

Summary

This PR migrates jest-mock type tests to TSTyche. The diff is hm.. There is no diff actually, these look like newly added files. Not sure if this is good for review. Or is that fine?

Test plan

The type tests should pass.

Copy link

netlify bot commented Feb 7, 2024

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 19cb53b
🔍 Latest deploy log https://app.netlify.com/sites/jestjs/deploys/65d43850db35820008e18912
😎 Deploy Preview https://deploy-preview-14884--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -144,7 +144,10 @@ function typeTests() {

verifyInstalledTypescript();

execa.sync('yarn', ['test-types'], {cwd, stdio: 'inherit'});
execa.sync('yarn', ['test-ts', '--selectProjects', 'type-tests'], {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overlooked it before. Current script runs TSTyche as well. This is just waste of time, because yarn tstyche --target 5.0,current already tested on TypeScript 5.0.

((a: string, b?: number | undefined) => boolean) | undefined
>();

expect(mockFn.getMockImplementation('some-mock')).type.toRaiseError();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.toRaiseError() check the error message, but I avoid these in this PR. 1. This is exactly what was tested before, so there is no regression. 2. The intention of this test is not about error message, the goal is to test this:

expect(mockFn.getMockImplementation).type.not.toBeCallableWith('some-mock');

The ability matchers, like matchers like .toBeCallableWith(), should ship with TSTyche 2. So I will use them here later.

mockFunction.mockImplementation((a: boolean, b?: number) => true),
).type.toRaiseError();

expect(someFunction).type.toBeAssignable(mockFunction);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types of two expressions compared. That’s an improvement. Nice to see!


// FunctionLike
test('MethodKeys', () => {
expect<MethodLikeKeys<SomeClass>>().type.toEqual<'methodA' | 'methodB'>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two types are compared directly. No need of declare const in utility type tests. Also nice improvement.


test('models typings of mocked function', () => {
// eslint-disable-next-line @typescript-eslint/ban-types
expect(fn()).type.toMatch<Function>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.toMatch() instead of assignability. This checks that fn() extends from the Function type. Perhaps .toExtend() would be better name for this matcher. In a way it is almost the same.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great stuff as always. thanks!

@SimenB SimenB merged commit c318478 into jestjs:main Feb 20, 2024
72 of 73 checks passed
@mrazauskas mrazauskas deleted the migrate-jest-mock-type-tests branch February 20, 2024 07:54
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants