| 12 | import type {JasmineMatchersObject} from './types'; |
| 13 | |
| 14 | export 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 | } |