You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm migrating my project from Jest to ViTest, pretty impressed by the framework so far. I do have a problem with snapshots though, I cannot have them working at all.
Here's a test
test('when user has access then service call should match snapshot', async () => {
extService.find = vi.fn().mockReturnValueOnce([someConstant]);
const actualResult = await someLib.userCan(Permissions.Read, Entities.Abc, ['SomeRole']);
expect(mongoExtService.find).toMatchSnapshot();
});
When using Jest it would save the snapshot of what extService received, but with ViTest it just saves [functions]
So instead of something like this
exports[`Given userCan when user has access then service call should match snapshot 1`] = `
[MockFunction] {
"calls": Array [
Array [
"permissions",
Object {
"code": "users",
},
Object {},
Object {
"code": 1,
},
100,
0,
],
],
"results": Array [
Object {
"type": "return",
"value": Promise {},
},
],
}
`;
I now have this, in my snapshot
exports[`Given userCan > when user has access then service call should match snapshot 1`] = `[Function]`;
If I do replace toMatchSnapshot by toHaveBeenCalledWith I then see the object that I was expecting to see in my snapshot.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi all!
I'm migrating my project from Jest to ViTest, pretty impressed by the framework so far. I do have a problem with snapshots though, I cannot have them working at all.
Here's a test
When using Jest it would save the snapshot of what
extService
received, but with ViTest it just saves [functions]So instead of something like this
I now have this, in my snapshot
If I do replace
toMatchSnapshot
bytoHaveBeenCalledWith
I then see the object that I was expecting to see in my snapshot.If anyone has any idea, I'd appreciated.
Thank you in advance!
Beta Was this translation helpful? Give feedback.
All reactions