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

Migrate more type tests to TSTyche #1989

Merged
merged 3 commits into from Feb 26, 2024

Conversation

mrazauskas
Copy link

Following up #1988

This PR migrates more type tests to TSTyche.

Comment on lines -21 to -22
// TODO: Turn on once https://github.com/Microsoft/dtslint/issues/19 is resolved.
Range; // $ ExpectType (start?: number | undefined, end?: number | undefined, step?: number | undefined) => Indexed<number>
Copy link
Author

Choose a reason for hiding this comment

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

Notice that few assertions were disabled by adding a space: // $ ExpectType instead of // $ExpectType. I think now they work as expected.

Copy link
Member

Choose a reason for hiding this comment

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

Range did change in 5.x in that way yes 😉

@mrazauskas
Copy link
Author

mrazauskas commented Feb 22, 2024

One question. I work on List and Map tests. There are cases like this:

// $ExpectError
List().size = 10;

// $ExpectError
Map().size = 10;

This makes sure that .size is readonly. Triggering errors is not always the best testing strategy, because it is not clear what is being tested. Currently in TSTyche I can write these tests like this:

expect(List()).type.toMatch<{ readonly size: number }>();

expect(Map()).type.toMatch<{ readonly size: number }>();

Somewhat better, but still indirect. Here is new idea:

expect(List().size).type.toBeReadonly();

expect(Map().size).type.toBeReadonly();

UPDATE: it is not so simple. I mean, readonly modifier is easy to detect, but other readonly constructs are not so obvious (like Readonly utility type or ReadonlyArray). So I will step back from this idea for now.

Easy to read (and to implement). @jdeniau What you think?

// $ExpectType boolean
has({ x: 10, y: 20 }, 'x');
}
expect(set([1, 2, 3], 0, 'a')).type.toRaiseError();
Copy link
Author

Choose a reason for hiding this comment

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

Here and elsewhere .not.toBeCallableWith() matcher should be used instead of .toRaiseError(). Keeping it as it was, but I will come back after implementing .toBeCallableWith():

expect(set).type.not.toBeCallableWith([1, 2, 3], 0, 'a');

@jdeniau jdeniau linked an issue Feb 23, 2024 that may be closed by this pull request
@jdeniau
Copy link
Member

jdeniau commented Feb 23, 2024

expect(List().size).type.toBeReadonly();

seems easy to read, so it's a 👍 for me

@mrazauskas
Copy link
Author

Thanks for heads up regarding .toBeReadonly(). Noted it in my todo list.

If all looks good here, this PR can be merged.

@jdeniau
Copy link
Member

jdeniau commented Feb 26, 2024

Unrelated failing tests (error in dist-stats, probably with an external call)

@jdeniau jdeniau merged commit bbd8fc9 into immutable-js:5.x Feb 26, 2024
4 of 5 checks passed
@mrazauskas mrazauskas deleted the migrate-to-tstyche branch February 26, 2024 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Moving off deprecated dependencies
2 participants