diff --git a/CHANGELOG.md b/CHANGELOG.md index 1116fd8a46d9..8554348f954b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - `[jest-cli]` Handle missing `numTodoTests` in test results ([#7779](https://github.com/facebook/jest/pull/7779)) - `[jest-runtime]` Exclude setup/teardown files from coverage report ([#7790](https://github.com/facebook/jest/pull/7790) - `[babel-jest]` Throw an error if `babel-jest` tries to transform a file ignored by Babel ([#7797](https://github.com/facebook/jest/pull/7797)) +- `[babel-plugin-jest-hoist]` Ignore TS type references when looking for out-of-scope references ([#7799](https://github.com/facebook/jest/pull/7799) ### Chore & Maintenance diff --git a/e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts b/e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts index e92369af9684..820294d1973e 100644 --- a/e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts +++ b/e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts @@ -12,6 +12,8 @@ import {Color} from '../types'; import {color} from '../entry'; +jest.mock('some-module', () => ({} as Partial<{}>), {virtual: true}); + jest.mock('../entry', () => { const color: Color = 'blue'; return {color}; diff --git a/packages/babel-plugin-jest-hoist/src/index.js b/packages/babel-plugin-jest-hoist/src/index.js index 13f9c2bdcc00..9445cffde661 100644 --- a/packages/babel-plugin-jest-hoist/src/index.js +++ b/packages/babel-plugin-jest-hoist/src/index.js @@ -76,7 +76,7 @@ const IDVisitor = { ReferencedIdentifier(path) { this.ids.add(path); }, - blacklist: ['TypeAnnotation', 'TSTypeAnnotation'], + blacklist: ['TypeAnnotation', 'TSTypeAnnotation', 'TSTypeReference'], }; const FUNCTIONS: Object = Object.create(null);