Skip to content

Commit

Permalink
chore: add snapshotState to local expect
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jan 1, 2023
1 parent 2216429 commit fbebc41
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/vitest/src/integrations/chai/index.ts
Expand Up @@ -21,15 +21,20 @@ export function createExpect(test?: Test) {
expect.getState = () => getState<MatcherState>(expect)
expect.setState = state => setState(state as Partial<MatcherState>, expect)

// @ts-expect-error global is not typed
const globalState = getState(globalThis[GLOBAL_EXPECT]) || {}

setState<MatcherState>({
// this should also add "snapshotState" that is added conditionally
...globalState,
assertionCalls: 0,
isExpectingAssertions: false,
isExpectingAssertionsError: null,
expectedAssertionsNumber: null,
expectedAssertionsNumberErrorGen: null,
environment: getCurrentEnvironment(),
testPath: test?.suite.file?.filepath,
currentTestName: test ? getFullName(test) : undefined,
testPath: test ? test.suite.file?.filepath : globalState.testPath,
currentTestName: test ? getFullName(test) : globalState.currentTestName,
}, expect)

// @ts-expect-error untyped
Expand Down
9 changes: 8 additions & 1 deletion test/core/test/local-context.test.ts
Expand Up @@ -25,7 +25,14 @@ describe('local test context works with implicit type', () => {
it('works with implicit type', (context: LocalTestContext) => {
expect(context.bar).toBe('bar')
})
it.only('is chainable with implicit type', (context: LocalTestContext) => {
it('is chainable with implicit type', (context: LocalTestContext) => {
expect(context.bar).toBe('bar')
})
})

describe('context expect', () => {
it('has snapshotState', ({ expect: localExpect }) => {
expect(expect.getState().snapshotState).toBeDefined()
expect(localExpect.getState().snapshotState).toBeDefined()
})
})

0 comments on commit fbebc41

Please sign in to comment.