Skip to content

Commit a5f58b5

Browse files
authored
fix(jest-jasmine2, jest-types): remove jasmine types from @jest/types (#12125)
1 parent 0d0844a commit a5f58b5

File tree

8 files changed

+23
-25
lines changed

8 files changed

+23
-25
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- `[jest-environment-node]` [**BREAKING**] Migrate to ESM ([#12340](https://github.com/facebook/jest/pull/12340))
1313
- `[@jest/expect-utils]` New module exporting utils for `expect` ([#12323](https://github.com/facebook/jest/pull/12323))
1414
- `[jest-jasmine2, jest-runtime]` [**BREAKING**] Use `Symbol` to pass `jest.setTimeout` value instead of `jasmine` specific logic ([#12124](https://github.com/facebook/jest/pull/12124))
15+
- `[jest-jasmine2, jest-types]` [**BREAKING**] Move all `jasmine` specific types from `@jest/types` to its own package ([#12125](https://github.com/facebook/jest/pull/12125))
1516
- `[jest-snapshot]` [**BREAKING**] Migrate to ESM ([#12342](https://github.com/facebook/jest/pull/12342))
1617
- `[jest-worker]` [**BREAKING**] Allow only absolute `workerPath` ([#12343](https://github.com/facebook/jest/pull/12343))
1718

packages/jest-jasmine2/src/errorOnPrivate.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import type {Global} from '@jest/types';
99
import {ErrorWithStack} from 'jest-util';
10-
import type {Jasmine} from './types';
1110

1211
type DisabledGlobalKeys = 'fail' | 'pending' | 'spyOn' | 'spyOnProperty';
1312

@@ -40,7 +39,7 @@ const disabledJasmineMethods: Record<DisabledJasmineMethodsKeys, string> = {
4039
};
4140

4241
export function installErrorOnPrivate(global: Global.Global): void {
43-
const jasmine = global.jasmine as Jasmine;
42+
const jasmine = global.jasmine;
4443

4544
(Object.keys(disabledGlobals) as Array<DisabledGlobalKeys>).forEach(
4645
functionName => {

packages/jest-jasmine2/src/jasmineAsyncInstall.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export default function jasmineAsyncInstall(
230230
globalConfig: Config.GlobalConfig,
231231
global: Global.Global,
232232
): void {
233-
const jasmine = global.jasmine as Jasmine;
233+
const jasmine = global.jasmine;
234234
const mutex = throat(globalConfig.maxConcurrency);
235235

236236
const env = jasmine.getEnv();

packages/jest-jasmine2/src/jestExpect.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
/* eslint-disable local/prefer-spread-eventually */
99

10-
import type {Global} from '@jest/types';
1110
import {MatcherState, expect} from 'expect';
1211
import {
1312
addSerializer,
@@ -16,9 +15,7 @@ import {
1615
toThrowErrorMatchingInlineSnapshot,
1716
toThrowErrorMatchingSnapshot,
1817
} from 'jest-snapshot';
19-
import type {Jasmine, JasmineMatchersObject, RawMatcherFn} from './types';
20-
21-
declare const global: Global.Global;
18+
import type {JasmineMatchersObject, RawMatcherFn} from './types';
2219

2320
export default function jestExpect(config: {expand: boolean}): void {
2421
global.expect = expect;
@@ -31,7 +28,7 @@ export default function jestExpect(config: {expand: boolean}): void {
3128
});
3229
expect.addSnapshotSerializer = addSerializer;
3330

34-
const jasmine = global.jasmine as Jasmine;
31+
const jasmine = global.jasmine;
3532
jasmine.anything = expect.anything;
3633
jasmine.any = expect.any;
3734
jasmine.objectContaining = expect.objectContaining;

packages/jest-jasmine2/src/setup_jest_globals.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import type {Config, Global} from '@jest/types';
8+
import type {Config} from '@jest/types';
99
import {expect} from 'expect';
1010
import {
1111
SnapshotState,
@@ -18,9 +18,6 @@ import type {
1818
default as JasmineSpec,
1919
SpecResult,
2020
} from './jasmine/Spec';
21-
import type {Jasmine} from './types';
22-
23-
declare const global: Global.Global;
2421

2522
export type SetupOptions = {
2623
config: Config.ProjectConfig;
@@ -66,7 +63,7 @@ const addAssertionErrors = (result: SpecResult) => {
6663
};
6764

6865
const patchJasmine = () => {
69-
(global.jasmine as Jasmine).Spec = (realSpec => {
66+
global.jasmine.Spec = (realSpec => {
7067
class Spec extends realSpec {
7168
constructor(attr: Attributes) {
7269
const resultCallback = attr.resultCallback;
@@ -85,7 +82,7 @@ const patchJasmine = () => {
8582
}
8683

8784
return Spec;
88-
})((global.jasmine as Jasmine).Spec);
85+
})(global.jasmine.Spec);
8986
};
9087

9188
export default async function setupJestGlobals({

packages/jest-jasmine2/src/types.ts

+13
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ declare global {
9696
namespace NodeJS {
9797
interface Global {
9898
expect: Expect;
99+
jasmine: Jasmine;
100+
}
101+
}
102+
}
103+
104+
declare module '@jest/types' {
105+
namespace Global {
106+
interface GlobalAdditions {
107+
jasmine: Jasmine;
108+
fail: () => void;
109+
pending: () => void;
110+
spyOn: () => void;
111+
spyOnProperty: () => void;
99112
}
100113
}
101114
}

packages/jest-jasmine2/tsconfig.json

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"extends": "../../tsconfig",
33
"compilerOptions": {
4+
// we don't want `@types/jest` to be referenced
5+
"types": [],
46
"rootDir": "src",
57
"outDir": "build"
68
},

packages/jest-types/src/Global.ts

-11
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ export type EachTestFn<EachCallback extends TestCallback> = (
5151
...args: ReadonlyArray<any>
5252
) => ReturnType<EachCallback>;
5353

54-
// TODO: Get rid of this at some point
55-
type Jasmine = {
56-
_DEFAULT_TIMEOUT_INTERVAL?: number;
57-
addMatchers: (matchers: Record<string, unknown>) => void;
58-
};
59-
6054
type Each<EachCallback extends TestCallback> =
6155
| ((
6256
table: EachTable,
@@ -124,11 +118,6 @@ export interface TestFrameworkGlobals {
124118

125119
export interface GlobalAdditions extends TestFrameworkGlobals {
126120
__coverage__: CoverageMapData;
127-
jasmine: Jasmine;
128-
fail: () => void;
129-
pending: () => void;
130-
spyOn: () => void;
131-
spyOnProperty: () => void;
132121
}
133122

134123
export interface Global

0 commit comments

Comments
 (0)