From 6bfd42e6541a6fb1854d0220ae94d84ab4a0c91d Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 16 Feb 2022 18:16:43 +0100 Subject: [PATCH 1/3] chore: re-export `AsymmetricMatcher` from `@jest/expect` --- packages/jest-expect/README.md | 2 +- packages/jest-expect/src/index.ts | 3 ++- packages/jest-jasmine2/src/types.ts | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/jest-expect/README.md b/packages/jest-expect/README.md index ed84274db617..81cf1b41a8bb 100644 --- a/packages/jest-expect/README.md +++ b/packages/jest-expect/README.md @@ -1,5 +1,5 @@ # @jest/expect -This package extends `expect` library with `jest-snapshot` matchers. It export `jestExpect` object, which can be used as standalone replacement of `expect`, and `createJestExpect` factory function, which returns an instance of `jestExpect`. +This package extends `expect` library with `jest-snapshot` matchers. It exports `jestExpect` object, which can be used as standalone replacement of `expect`. The `jestExpect` function used in [Jest](https://jestjs.io/). You can find its documentation [on Jest's website](https://jestjs.io/docs/expect). diff --git a/packages/jest-expect/src/index.ts b/packages/jest-expect/src/index.ts index 3086a8fe447a..31c03d1fcadc 100644 --- a/packages/jest-expect/src/index.ts +++ b/packages/jest-expect/src/index.ts @@ -15,9 +15,10 @@ import { } from 'jest-snapshot'; import type {JestExpect} from './types'; +export type {AsymmetricMatchers, MatcherFunction, MatcherState} from 'expect'; export type {JestExpect} from './types'; -export function createJestExpect(): JestExpect { +function createJestExpect(): JestExpect { expect.extend({ toMatchInlineSnapshot, toMatchSnapshot, diff --git a/packages/jest-jasmine2/src/types.ts b/packages/jest-jasmine2/src/types.ts index b6f3e147b8bb..c7197e1320e8 100644 --- a/packages/jest-jasmine2/src/types.ts +++ b/packages/jest-jasmine2/src/types.ts @@ -6,7 +6,7 @@ */ import type {AssertionError} from 'assert'; -import type {JestExpect} from '@jest/expect'; +import type {AsymmetricMatchers, JestExpect} from '@jest/expect'; import type CallTracker from './jasmine/CallTracker'; import type Env from './jasmine/Env'; import type JsApiReporter from './jasmine/JsApiReporter'; @@ -69,7 +69,7 @@ export type Jasmine = { version: string; testPath: string; addMatchers: (matchers: JasmineMatchersObject) => void; -} & JestExpect & +} & AsymmetricMatchers & typeof globalThis; declare global { From 4a4c87d350b72ae9857fbcdbb643385beb0d4062 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 16 Feb 2022 18:20:45 +0100 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74ecb66b586f..9e834f9e62b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ - `[jest-environment-jsdom]` [**BREAKING**] Upgrade jsdom to 19.0.0 ([#12290](https://github.com/facebook/jest/pull/12290)) - `[jest-environment-jsdom]` [**BREAKING**] Add default `browser` condition to `exportConditions` for `jsdom` environment ([#11924](https://github.com/facebook/jest/pull/11924)) - `[jest-environment-node]` [**BREAKING**] Add default `node` and `node-addon` conditions to `exportConditions` for `node` environment ([#11924](https://github.com/facebook/jest/pull/11924)) -- `[@jest/expect]` [**BREAKING**] New module which extends `expect` with `jest-snapshot` matchers ([#12404](https://github.com/facebook/jest/pull/12404)) +- `[@jest/expect]` New module which extends `expect` with `jest-snapshot` matchers ([#12404](https://github.com/facebook/jest/pull/12404), [#12410](https://github.com/facebook/jest/pull/12410)) - `[@jest/expect-utils]` New module exporting utils for `expect` ([#12323](https://github.com/facebook/jest/pull/12323)) - `[jest-resolver]` [**BREAKING**] Add support for `package.json` `exports` ([11961](https://github.com/facebook/jest/pull/11961)) - `[jest-resolve, jest-runtime]` Add support for `data:` URI import and mock ([#12392](https://github.com/facebook/jest/pull/12392)) @@ -36,6 +36,7 @@ - `[docs, examples]` Update React examples to match with the new React guidelines for code examples ([#12217](https://github.com/facebook/jest/pull/12217)) - `[expect]` [**BREAKING**] Remove support for importing `build/utils` ([#12323](https://github.com/facebook/jest/pull/12323)) - `[expect]` [**BREAKING**] Migrate to ESM ([#12344](https://github.com/facebook/jest/pull/12344)) +- `[expect]` [**BREAKING**] Snapshot matcher types are moved to `@jest/expect` ([#12404](https://github.com/facebook/jest/pull/12404)) - `[jest-cli]` Update `yargs` to v17 ([#12357](https://github.com/facebook/jest/pull/12357)) - `[jest-config]` [**BREAKING**] Remove `getTestEnvironment` export ([#12353](https://github.com/facebook/jest/pull/12353)) - `[@jest/core]` Use `index.ts` instead of `jest.ts` as main export ([#12329](https://github.com/facebook/jest/pull/12329)) From 2778da0140e041fb5679319d3afd60425409c675 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 16 Feb 2022 18:23:29 +0100 Subject: [PATCH 3/3] chore: do not add entire globalThis to Jasmine --- packages/jest-jasmine2/src/types.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/jest-jasmine2/src/types.ts b/packages/jest-jasmine2/src/types.ts index c7197e1320e8..427f1aaefe4e 100644 --- a/packages/jest-jasmine2/src/types.ts +++ b/packages/jest-jasmine2/src/types.ts @@ -69,8 +69,7 @@ export type Jasmine = { version: string; testPath: string; addMatchers: (matchers: JasmineMatchersObject) => void; -} & AsymmetricMatchers & - typeof globalThis; +} & AsymmetricMatchers & {process: NodeJS.Process}; declare global { namespace NodeJS {