diff --git a/CHANGELOG.md b/CHANGELOG.md index 02a4ee7443f6..90d3ba8bc6ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,7 +68,7 @@ - `[@jest/transform]`: Migrate to TypeScript ([#7918](https://github.com/facebook/jest/pull/7918), [#7945](https://github.com/facebook/jest/pull/7945)) - `[docs]` Add missing import to docs ([#7928](https://github.com/facebook/jest/pull/7928)) - `[jest-resolve-dependencies]`: Migrate to TypeScript ([#7922](https://github.com/facebook/jest/pull/7922)) -- `[expect]`: Migrate to TypeScript ([#7919](https://github.com/facebook/jest/pull/7919)) +- `[expect]`: Migrate to TypeScript ([#7919](https://github.com/facebook/jest/pull/7919), [#8028](https://github.com/facebook/jest/pull/8028)) - `[jest-circus]`: Migrate to TypeScript ([#7916](https://github.com/facebook/jest/pull/7916)) - `[jest-phabricator]`: Migrate to TypeScript ([#7965](https://github.com/facebook/jest/pull/7965)) - `[jest-runner]`: Migrate to TypeScript ([#7968](https://github.com/facebook/jest/pull/7968)) diff --git a/packages/expect/src/index.ts b/packages/expect/src/index.ts index 500b2f19945c..f5190881c118 100644 --- a/packages/expect/src/index.ts +++ b/packages/expect/src/index.ts @@ -11,7 +11,7 @@ import { AsyncExpectationResult, SyncExpectationResult, ExpectationResult, - MatcherState, + MatcherState as JestMatcherState, MatchersObject, RawMatcherFn, ThrowingMatcherFn, @@ -61,7 +61,7 @@ const createToThrowErrorMatchingSnapshotMatcher = function( matcher: RawMatcherFn, ) { return function( - this: MatcherState, + this: JestMatcherState, received: any, testNameOrInlineSnapshot?: string, ) { @@ -241,7 +241,7 @@ const makeThrowingMatcher = ( let throws = true; const utils = {...matcherUtils, iterableEquality, subsetEquality}; - const matcherContext: MatcherState = { + const matcherContext: JestMatcherState = { // When throws is disabled, the matcher will not throw errors during test // execution but instead add them to the global matcher state. If a // matcher throws, test execution is normally stopped immediately. The @@ -407,4 +407,11 @@ expect.getState = getState; expect.setState = setState; expect.extractExpectedAssertionsErrors = extractExpectedAssertionsErrors; -export = expect as Expect; +const expectExport = expect as Expect; + +// eslint-disable-next-line no-redeclare +namespace expectExport { + export type MatcherState = JestMatcherState; +} + +export = expectExport; diff --git a/packages/jest-snapshot/package.json b/packages/jest-snapshot/package.json index 2f42a9bbc86b..85acb858aee4 100644 --- a/packages/jest-snapshot/package.json +++ b/packages/jest-snapshot/package.json @@ -13,6 +13,7 @@ "@babel/types": "^7.0.0", "@jest/types": "^24.1.0", "chalk": "^2.0.1", + "expect": "^24.1.0", "jest-diff": "^24.0.0", "jest-matcher-utils": "^24.0.0", "jest-message-util": "^24.0.0", diff --git a/packages/jest-snapshot/src/index.ts b/packages/jest-snapshot/src/index.ts index 0ed61078506c..0f6728f4ff60 100644 --- a/packages/jest-snapshot/src/index.ts +++ b/packages/jest-snapshot/src/index.ts @@ -6,8 +6,9 @@ */ import fs from 'fs'; -import {Config, Matchers} from '@jest/types'; +import {Config} from '@jest/types'; import {FS as HasteFS} from 'jest-haste-map'; +import {MatcherState} from 'expect'; import diff from 'jest-diff'; import {EXPECTED_COLOR, matcherHint, RECEIVED_COLOR} from 'jest-matcher-utils'; @@ -21,8 +22,7 @@ import SnapshotState from './State'; import {addSerializer, getSerializers} from './plugins'; import * as utils from './utils'; -// TODO: use MatcherState directly from `expect` once whole project is migrated -type Context = Matchers.MatcherState & { +type Context = MatcherState & { snapshotState: SnapshotState; }; diff --git a/packages/jest-snapshot/tsconfig.json b/packages/jest-snapshot/tsconfig.json index 2ed3fb0d58dc..dba6475fc19c 100644 --- a/packages/jest-snapshot/tsconfig.json +++ b/packages/jest-snapshot/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "build" }, "references": [ + {"path": "../expect"}, {"path": "../jest-diff"}, {"path": "../jest-haste-map"}, {"path": "../jest-matcher-utils"}, diff --git a/packages/jest-types/src/Matchers.ts b/packages/jest-types/src/Matchers.ts deleted file mode 100644 index f1a4b9b94ce9..000000000000 --- a/packages/jest-types/src/Matchers.ts +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// TODO: Remove this when whole project is migrated - -import {Path} from './Config'; - -type Tester = (a: any, b: any) => boolean | undefined; - -export type MatcherState = { - assertionCalls: number; - currentTestName?: string; - dontThrow?: () => void; - error?: Error; - equals: ( - a: unknown, - b: unknown, - customTesters?: Array, - strictCheck?: boolean, - ) => boolean; - expand?: boolean; - expectedAssertionsNumber?: number; - isExpectingAssertions?: boolean; - isNot: boolean; - promise: string; - suppressedErrors: Array; - testPath?: Path; - // This is output from `jest-matcher-utils` plus iterableEquality, subsetEquality - // Type it correctly when moving it to `expect` - utils: { - printExpected: (value: unknown) => string; - printReceived: (value: unknown) => string; - iterableEquality: Tester; - subsetEquality: Tester; - }; -}; diff --git a/packages/jest-types/src/index.ts b/packages/jest-types/src/index.ts index eb28f92c93c5..dd30d701fb87 100644 --- a/packages/jest-types/src/index.ts +++ b/packages/jest-types/src/index.ts @@ -6,8 +6,7 @@ */ import * as Config from './Config'; -import * as Matchers from './Matchers'; import * as TestResult from './TestResult'; import * as Global from './Global'; -export {Config, Matchers, TestResult, Global}; +export {Config, TestResult, Global};