-
|
Currently we are using jest-snapshot for custom snapshot matchers in here We are planning to run the tests also in browser mode, but then this breaks because jest-snapshot is not made for browser environment. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
The abstraction of vitest/packages/vitest/src/integrations/snapshot/chai.ts Lines 64 to 71 in a288c1e It looks like technically you can customize it like this https://stackblitz.com/edit/vitest-dev-vitest-3sb8oxer?file=test%2Frepro.test.ts import { expect, test, chai } from 'vitest';
test('foo', () => {
chai.util.addMethod(
chai.Assertion.prototype,
'toMatchSnapshot2',
function (this: any, ...args: any[]) {
// modify received object
const object = chai.util.flag(this, 'object');
chai.util.flag(this, 'object', { wrapped: object });
// call orignal assertion
return this.toMatchSnapshot(...args);
}
);
expect({ hello: 'world' }).toMatchSnapshot2();
});But the error stacktrace when unmatched seems off. I'm not sure how it can be handled in user land. Probably there is a way to provide something better officially, but I don't know what that is at the moment. Please feel free to create a feature request for starter. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @hi-ogawa regarding #7848 |
Beta Was this translation helpful? Give feedback.
The abstraction of
@vitest/snapshotis different fromjest-snapshotas it's internally implemented as chai method:vitest/packages/vitest/src/integrations/snapshot/chai.ts
Lines 64 to 71 in a288c1e
It looks like technically you can customize it like this https://stackblitz.com/edit/vitest-dev-vitest-3sb8oxer?file=test%2Frepro.test.ts