Skip to content

Commit

Permalink
chore: export matcherstate from expect
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Mar 3, 2019
1 parent bcc2b10 commit 807a11e
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 50 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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};

0 comments on commit 807a11e

Please sign in to comment.