Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export matcher state from expect #8028

Merged
merged 1 commit into from Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -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))
Expand Down
15 changes: 11 additions & 4 deletions packages/expect/src/index.ts
Expand Up @@ -11,7 +11,7 @@ import {
AsyncExpectationResult,
SyncExpectationResult,
ExpectationResult,
MatcherState,
MatcherState as JestMatcherState,
MatchersObject,
RawMatcherFn,
ThrowingMatcherFn,
Expand Down Expand Up @@ -61,7 +61,7 @@ const createToThrowErrorMatchingSnapshotMatcher = function(
matcher: RawMatcherFn,
) {
return function(
this: MatcherState,
this: JestMatcherState,
received: any,
testNameOrInlineSnapshot?: string,
) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
1 change: 1 addition & 0 deletions packages/jest-snapshot/package.json
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-snapshot/src/index.ts
Expand Up @@ -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';
Expand All @@ -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;
};

Expand Down
1 change: 1 addition & 0 deletions packages/jest-snapshot/tsconfig.json
Expand Up @@ -5,6 +5,7 @@
"outDir": "build"
},
"references": [
{"path": "../expect"},
{"path": "../jest-diff"},
{"path": "../jest-haste-map"},
{"path": "../jest-matcher-utils"},
Expand Down
40 changes: 0 additions & 40 deletions packages/jest-types/src/Matchers.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/jest-types/src/index.ts
Expand Up @@ -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};