diff --git a/packages/vitest/src/integrations/snapshot/chai.ts b/packages/vitest/src/integrations/snapshot/chai.ts index 8956ac479..842a20382 100644 --- a/packages/vitest/src/integrations/snapshot/chai.ts +++ b/packages/vitest/src/integrations/snapshot/chai.ts @@ -41,7 +41,7 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => { utils.addMethod( chai.Assertion.prototype, 'toMatchInlineSnapshot', - function(this: Record, properties?: object, inlineSnapshot?: string, message?: string) { + function __VITEST_INLINE_SNAPSHOT__(this: Record, properties?: object, inlineSnapshot?: string, message?: string) { const expected = utils.flag(this, 'object') if (typeof properties === 'string') { message = inlineSnapshot @@ -62,7 +62,7 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => { utils.addMethod( chai.Assertion.prototype, 'toThrowErrorMatchingInlineSnapshot', - function(this: Record, inlineSnapshot: string, message: string) { + function __VITEST_INLINE_SNAPSHOT__(this: Record, inlineSnapshot: string, message: string) { const expected = utils.flag(this, 'object') getSnapshotClient().assert(getErrorString(expected), message, true, undefined, inlineSnapshot) }, diff --git a/packages/vitest/src/integrations/snapshot/port/state.ts b/packages/vitest/src/integrations/snapshot/port/state.ts index f8a5ffde3..d4da8cadc 100644 --- a/packages/vitest/src/integrations/snapshot/port/state.ts +++ b/packages/vitest/src/integrations/snapshot/port/state.ts @@ -97,8 +97,10 @@ export default class SnapshotState { const error = options.error || new Error('Unknown error') const stacks = parseStacktrace(error) stacks.forEach(i => i.file = slash(i.file)) - const stackIndex = stacks.findIndex(i => i.method === 'Proxy.methodWrapper') - const stack = stackIndex !== -1 ? stacks[stackIndex + 1] : null + // inline snapshot function is called __VITEST_INLINE_SNAPSHOT__ + // in integrations/snapshot/chai.ts + const stackIndex = stacks.findIndex(i => i.method === 'Proxy.__VITEST_INLINE_SNAPSHOT__') + const stack = stackIndex !== -1 ? stacks[stackIndex + 2] : null if (!stack) { throw new Error( 'Vitest: Couldn\'t infer stack frame for inline snapshot.',