[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

feat(expect): add getState support (#457)

authored by

Vladimir and committed by
GitHub
(Jan 6, 2022, 11:23 PM +0800) 34be39e6 acc7fecb

+9 -2
+3 -1
packages/vitest/src/index.ts
··· 2 2 Plugin as PrettyFormatPlugin, 3 3 } from 'pretty-format' 4 4 import type { Any, Anything, ArrayContaining, ObjectContaining, StringMatching } from './integrations/chai/jest-asymmetric-matchers' 5 - import type { MatchersObject } from './integrations/chai/types' 5 + import type { MatcherState, MatchersObject } from './integrations/chai/types' 6 6 import type { InlineConfig } from './types' 7 7 8 8 type VitestInlineConfig = InlineConfig ··· 43 43 anything(): Anything 44 44 any(constructor: unknown): Any 45 45 addSnapshotSerializer(plugin: PrettyFormatPlugin): void 46 + getState(): MatcherState 47 + setState(state: Partial<MatcherState>): void 46 48 not: AsymmetricMatchersContaining 47 49 } 48 50
+3 -1
packages/vitest/src/runtime/run.ts
··· 2 2 import type { HookListener, ResolvedConfig, Suite, SuiteHooks, Task, TaskResult, Test } from '../types' 3 3 import { vi } from '../integrations/vi' 4 4 import { getSnapshotClient } from '../integrations/snapshot/chai' 5 - import { hasFailed, hasTests, partitionSuiteChildren } from '../utils' 5 + import { getFullName, hasFailed, hasTests, partitionSuiteChildren } from '../utils' 6 6 import { getState, setState } from '../integrations/chai/jest-expect' 7 7 import { getFn, getHooks } from './map' 8 8 import { rpc } from './rpc' ··· 68 68 isExpectingAssertionsError: null, 69 69 expectedAssertionsNumber: null, 70 70 expectedAssertionsNumberError: null, 71 + testPath: test.suite.file?.filepath, 72 + currentTestName: getFullName(test), 71 73 }) 72 74 await getFn(test)() 73 75 const { assertionCalls, expectedAssertionsNumber, expectedAssertionsNumberError, isExpectingAssertions, isExpectingAssertionsError } = getState()
+3
packages/vitest/src/integrations/chai/index.ts
··· 8 8 setState({ assertionCalls: assertionCalls + 1 }) 9 9 return chai.expect(value, message) 10 10 }) as Chai.ExpectStatic 11 + expect.getState = getState 12 + expect.setState = setState 13 + 11 14 Object.assign(expect, chai.expect) 12 15 13 16 export { chai, expect }