-
Notifications
You must be signed in to change notification settings - Fork 40
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
Create matchers for vitest
#139
Comments
I found this in the vitest docs: https://vitest.dev/guide/features.html#chai-and-jest-expect-compatibility When I set |
Hey, sorry for the late reply. Thank you @kldavis4 for finding and sharing the way to make While I see a raising popularity of |
It still doesn't work for me, even with test.globals set to true.
|
This is really excellent test utility, thank you to all who have contributed so far. On this point from the README: Lines 513 to 514 in c6896a3
One problem here is the Vitest “Jest” matcher utils are a much smaller subset of the actual Jest matcher utils (which also rely on other Jest packages like jest-diff). ✅ If the expectation passes there is no problem, the matchers work as expected with vitest. ❌ However if the expectations then
At this point Vitest runner will bail:
Happy to stick my hand up to make a contribution. My thoughts are there are a few possibilities:
In the very short term I think either the limitations should be documented -or- Vitest not be officially documented as supported for just the matchers. @colesiegel On the typings question, I hope you got this resolved? Sharing my configuration in case it helps:
vitest.config.ts: import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true,
mockReset: true,
setupFiles: ['./awsSdkClientMatchers.ts'],
},
}); awsSdkClientMatchers.ts: import 'aws-sdk-client-mock-jest'; tsconfig.json: {
"extends": "@tsconfig/node18/tsconfig",
"compilerOptions": {
"allowJs": true,
"lib": ["ESNext"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"noEmit": true,
"types": ["vitest/globals"]
}
} |
@m-radzikowski Can this be re-opened? Vitest matchers don't yet exist for this project, and only kind-of work as a side effect of Vitest being very diligent about being Jest-compatable. Dedicated Vitest matchers would go a long ways, keeping the issue open may help with fishing for a contribution 🤔 |
This will be solved when #231 is merged. |
I still see this with 4.1.0. It works when running the tests but TS is not happy in vscode. Any chance someone knows how to fix it? Using import { DynamoDBDocumentClient, UpdateCommand } from '@aws-sdk/lib-dynamodb';
import { mockClient } from 'aws-sdk-client-mock';
import 'aws-sdk-client-mock-jest/vitest';
import { beforeEach, describe, expect, it } from 'vitest';
describe('something', () => {
const ddbMock = mockClient(DynamoDBDocumentClient);
beforeEach(() => {
ddbMock.reset();
});
it('something', async () => {
expect(ddbMock).toHaveReceivedCommandWith(UpdateCommand, {});
});
}); |
Yes I am getting the same, the tests will run ok, but show errors in VSCode on the expect lines.
|
You can also fix TS issues by declaring the types in a vitest.d.ts file if you don't want to keep your test tidier
|
Hello and thanks for this great lib 🙌
On my project we went from
jest
tovitest
, mainly for performances. Sadly, we lost thetoHaveReceivedCommand
matchers in the process 🥲Would be awesome to have them for
vitest
as well! Maybe it was the aim of separatingjest
matchers in another lib in the first place ?See https://vitest.dev/guide/extending-matchers.html
Cheers !
The text was updated successfully, but these errors were encountered: