UNPKG

histoire

Version:

A fast story book powered by Vite

3 lines • 2.44 kB
/** Standalone expect implementation and shared assertion state for story iframes. */ export declare const STORY_EXPECT_CODE = "\nchai.use(JestExtend)\nchai.use(JestChaiExpect)\nchai.use(JestAsymmetricMatchers)\n\n/** Creates an assertion function with isolated counters and Vitest matcher extensions. */\nexport function createExpect() {\n /** Binds each assertion to the active task for soft failures and tracked promises. */\n const expect = (value, message) => {\n const { assertionCalls = 0 } = getState(expect) ?? {}\n setState({ assertionCalls: assertionCalls + 1 }, expect)\n return chai.expect(value, message).withContext({\n 'vitest-test': globalThis.__vitest_worker__?.current,\n })\n }\n\n Object.assign(expect, chai.expect)\n Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT])\n\n expect.getState = () => getState(expect)\n expect.setState = state => setState(state, expect)\n\n setState({\n assertionCalls: 0,\n isExpectingAssertions: false,\n isExpectingAssertionsError: null,\n expectedAssertionsNumber: null,\n expectedAssertionsNumberErrorGen: null,\n currentTestName: '',\n }, expect)\n\n expect.assert = chai.assert\n expect.extend = matchers => chai.expect.extend(expect, matchers)\n expect.addEqualityTesters = customTesters => addCustomEqualityTesters(customTesters)\n expect.soft = (...args) => expect(...args).withContext({ soft: true })\n expect.unreachable = message => {\n chai.assert.fail(`expected${message ? ` \"${message}\" ` : ' '}not to be reached`)\n }\n\n chai.util.addMethod(expect, 'assertions', expected => {\n const errorGen = () => new Error(`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`)\n expect.setState({\n expectedAssertionsNumber: expected,\n expectedAssertionsNumberErrorGen: errorGen,\n })\n })\n\n chai.util.addMethod(expect, 'hasAssertions', () => {\n expect.setState({\n isExpectingAssertions: true,\n isExpectingAssertionsError: new Error('expected any number of assertion, but got none'),\n })\n })\n\n expect.extend(customMatchers)\n\n return expect\n}\n\nconst expect = globalThis[GLOBAL_EXPECT] ?? createExpect()\nif (globalThis[GLOBAL_EXPECT] !== expect) {\n Object.defineProperty(globalThis, GLOBAL_EXPECT, {\n value: expect,\n writable: true,\n configurable: true,\n })\n}\n"; //# sourceMappingURL=expect.d.ts.map