| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Sorry, something went wrong.
|
How is this going to work? expect(obj).toEqual<{
id: string
name: string
}>({
id: expect.any(String),
name: 'Amelia',
})Error:
|
Sorry, something went wrong.
Aha! Updated to use a DeeplyAllowMatchers. |
Sorry, something went wrong.
|
Hey @JoshuaKGoldberg! I'd love to include this in 3.2. Could you add some tests to test/typescript? Or should I take over this PR? Thank you! |
Sorry, something went wrong.
|
That's great, thank you @sheremet-va! Yes please - I'm a bit swamped this month and don't think I'll have time to figure out the test/typescript directory & add tests soon. |
Sorry, something went wrong.
|
Hello Vite! I just bumped to 3.2.0 and I ran into the same problem as #7016 (comment) Here is my code (details omitted for clarity): const expectedEventDraft: EventDraft = {
timestamp: expect.any(Number)
};
expect(onSubmit).toHaveBeenCalledWith(expectedEventDraft);
type EventDraft = {
readonly timestamp: number;
// ... other uninteresting properties
}
With an error:
What is the correct way to type this? I tried to use DeeplyAllowMatchers but it doesn't seem to be exported. |
Sorry, something went wrong.
Looks like we should expose it, I will create a PR |
Sorry, something went wrong.
|
I feel this change is breaking some legit types starting at Vitest 3.2: function expectMany<T>(value: { enabled: false } | { enable: true; data: T }) {
// In Vitest 3.2:
//
// Argument of type '{ enabled: false; } | { enable: true; data: T; }' is not assignable to parameter of type '{ enabled: false | AsymmetricMatcher<unknown, MatcherState>; } | { enable: true | AsymmetricMatcher<unknown, MatcherState>; data: AsymmetricMatcher<...> | DeeplyAllowMatchers<...>; }'.
// Type '{ enable: true; data: T; }' is not assignable to type '{ enabled: false | AsymmetricMatcher<unknown, MatcherState>; } | { enable: true | AsymmetricMatcher<unknown, MatcherState>; data: AsymmetricMatcher<...> | DeeplyAllowMatchers<...>; }'.
// Type '{ enable: true; data: T; }' is not assignable to type '{ enable: true | AsymmetricMatcher<unknown, MatcherState>; data: AsymmetricMatcher<unknown, MatcherState> | DeeplyAllowMatchers<T>; }'.
// Types of property 'data' are incompatible.
// Type 'T' is not assignable to type 'AsymmetricMatcher<unknown, MatcherState> | DeeplyAllowMatchers<T>'.
// Type 'T' is not assignable to type 'AsymmetricMatcher<unknown, MatcherState>'.ts(2345)
expect(value).toEqual(value);
} |
Sorry, something went wrong.
|
We heavily use the satisfies keyword in our tests. This change seems to make it impossible to use it. An abstract example, which demonstrates the problem: type Foo = {
bar: string;
foobar: {
foo: string;
bar: string;
}[]
}
const mockedFoo = vi.mocked(mock<Foo>()) // mock is from https://github.com/eratio08/vitest-mock-extended - but the important part is the expect statement
expect(mockedFoo).toHaveBeenCalledWith({
bar: "baz",
foobar: expect.any(Array),
} satisfies Foo)The error: |
Sorry, something went wrong.
|
We have some tests that pass expect.anything() to a constructor, now it is broken too. Typechecking now reports error of
Were we using expect.anything() improperly? const avroReaderStub = new AvroReader(expect.anything());
vi.mocked(avroReaderStub.hasNext).mockReturnValue(true);
const chunk = new Chunk(avroReaderStub as any, 0, 0, "log/00/2020/07/30/2300/");
assert.equal(chunk.hasNext(), true);
vi.mocked(avroReaderStub.hasNext).mockReturnValue(false);
assert.equal(chunk.hasNext(), false); |
Sorry, something went wrong.
|
@jeremymeng Your usage doesn't look right. If it can just work by new AvroReader({} as any), then that's not how you use expect.anything() https://vitest.dev/api/expect.html#expect-anything |
Sorry, something went wrong.
|
@hi-ogawa Thanks! Right, I don't think we care about the constructor argument for this test. I fixed the test by replacing expect.anything() with an object. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Description
Switches the two any types to unknown AsymmetricMatcher<unknown>, and updated APIs such as toEqual<T> to deeply allow those using a new DeeplyAllowMatchers<T>.
Sending as a draft for reference.
Fixes #7015.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
Documentation
Changesets