MCPcopy
hub / github.com/jestjs/jest / jestExpectAdapter

Function jestExpectAdapter

packages/jest-jasmine2/src/jestExpect.ts:14–42  ·  view source on GitHub ↗
(config: {expand: boolean})

Source from the content-addressed store, hash-verified

12import type {JasmineMatchersObject} from './types';
13
14export default function jestExpectAdapter(config: {expand: boolean}): void {
15 (globalThis as Global.Global).expect = jestExpect;
16 jestExpect.setState({expand: config.expand});
17
18 const jasmine = (globalThis as Global.Global).jasmine;
19 jasmine.anything = jestExpect.anything;
20 jasmine.any = jestExpect.any;
21 jasmine.objectContaining = jestExpect.objectContaining;
22 jasmine.arrayContaining = jestExpect.arrayContaining;
23 jasmine.stringMatching = jestExpect.stringMatching;
24
25 jasmine.addMatchers = (jasmineMatchersObject: JasmineMatchersObject) => {
26 const jestMatchersObject = Object.create(null);
27 for (const name of Object.keys(jasmineMatchersObject)) {
28 jestMatchersObject[name] = function (...args: Array<unknown>) {
29 // use "expect.extend" if you need to use equality testers (via this.equal)
30 const result = jasmineMatchersObject[name](null, null);
31 // if there is no 'negativeCompare', both should be handled by `compare`
32 const negativeCompare = result.negativeCompare || result.compare;
33
34 return this.isNot
35 ? negativeCompare.apply(null, args)
36 : result.compare.apply(null, args);
37 };
38 }
39
40 jestExpect.extend(jestMatchersObject);
41 };
42}

Callers

nothing calls this directly

Calls 4

extendMethod · 0.80
setStateMethod · 0.65
createMethod · 0.45
applyMethod · 0.45

Tested by

no test coverage detected