From 2ad75af20d39fec5545405759b556d30e53e25f1 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Mon, 6 Dec 2021 07:51:38 +0200 Subject: [PATCH 1/7] refactor: use Symbol to pass `testTimeout` --- packages/jest-jasmine2/src/index.ts | 8 ++++++-- packages/jest-jasmine2/src/jasmine/Env.ts | 12 +++++++----- packages/jest-jasmine2/src/jasmine/jasmineLight.ts | 4 +++- packages/jest-jasmine2/src/types.ts | 1 - packages/jest-runtime/src/index.ts | 8 ++------ 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/packages/jest-jasmine2/src/index.ts b/packages/jest-jasmine2/src/index.ts index efd1b01c30ec..7db6e8cdd340 100644 --- a/packages/jest-jasmine2/src/index.ts +++ b/packages/jest-jasmine2/src/index.ts @@ -23,6 +23,8 @@ const JASMINE = require.resolve('./jasmine/jasmineLight'); const jestEachBuildDir = path.dirname(require.resolve('jest-each')); +const testTimeoutSymbol = Symbol.for('TEST_TIMEOUT_SYMBOL'); + export default async function jasmine2( globalConfig: Config.GlobalConfig, config: Config.ProjectConfig, @@ -130,10 +132,12 @@ export default async function jasmine2( configurable: true, enumerable: true, get() { - return this._DEFAULT_TIMEOUT_INTERVAL; + // @ts-expect-error: https://github.com/Microsoft/TypeScript/issues/24587 + return environment.global[testTimeoutSymbol]; }, set(value) { - this._DEFAULT_TIMEOUT_INTERVAL = value; + // @ts-expect-error: https://github.com/Microsoft/TypeScript/issues/24587 + environment.global[testTimeoutSymbol] = value; }, }); } diff --git a/packages/jest-jasmine2/src/jasmine/Env.ts b/packages/jest-jasmine2/src/jasmine/Env.ts index 20975e1e9550..079b9c1fd974 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.ts +++ b/packages/jest-jasmine2/src/jasmine/Env.ts @@ -49,6 +49,8 @@ import type { import type {default as Spec, SpecResult} from './Spec'; import type Suite from './Suite'; +const testTimeoutSymbol = Symbol.for('TEST_TIMEOUT_SYMBOL'); + export default function (j$: Jasmine) { return class Env { specFilter: (spec: Spec) => boolean; @@ -510,7 +512,7 @@ export default function (j$: Jasmine) { queueableFn: { fn, timeout() { - return timeout || j$._DEFAULT_TIMEOUT_INTERVAL; + return timeout || (global as any)[testTimeoutSymbol]; }, }, throwOnExpectationFailure, @@ -622,7 +624,7 @@ export default function (j$: Jasmine) { currentDeclarationSuite.beforeEach({ fn: beforeEachFunction, timeout() { - return timeout || j$._DEFAULT_TIMEOUT_INTERVAL; + return timeout || (global as any)[testTimeoutSymbol]; }, }); }; @@ -631,7 +633,7 @@ export default function (j$: Jasmine) { currentDeclarationSuite.beforeAll({ fn: beforeAllFunction, timeout() { - return timeout || j$._DEFAULT_TIMEOUT_INTERVAL; + return timeout || (global as any)[testTimeoutSymbol]; }, }); }; @@ -640,7 +642,7 @@ export default function (j$: Jasmine) { currentDeclarationSuite.afterEach({ fn: afterEachFunction, timeout() { - return timeout || j$._DEFAULT_TIMEOUT_INTERVAL; + return timeout || (global as any)[testTimeoutSymbol]; }, }); }; @@ -649,7 +651,7 @@ export default function (j$: Jasmine) { currentDeclarationSuite.afterAll({ fn: afterAllFunction, timeout() { - return timeout || j$._DEFAULT_TIMEOUT_INTERVAL; + return timeout || (global as any)[testTimeoutSymbol]; }, }); }; diff --git a/packages/jest-jasmine2/src/jasmine/jasmineLight.ts b/packages/jest-jasmine2/src/jasmine/jasmineLight.ts index b54a79d8927e..1c25c06100df 100644 --- a/packages/jest-jasmine2/src/jasmine/jasmineLight.ts +++ b/packages/jest-jasmine2/src/jasmine/jasmineLight.ts @@ -40,10 +40,12 @@ import Timer from './Timer'; import createSpy from './createSpy'; import SpyRegistry from './spyRegistry'; +const testTimeoutSymbol = Symbol.for('TEST_TIMEOUT_SYMBOL'); + export const create = function (createOptions: Record): Jasmine { const j$ = {...createOptions} as Jasmine; - j$._DEFAULT_TIMEOUT_INTERVAL = createOptions.testTimeout || 5000; + (global as any)[testTimeoutSymbol] = createOptions.testTimeout || 5000; j$.getEnv = function () { const env = (j$.currentEnv_ = j$.currentEnv_ || new j$.Env()); diff --git a/packages/jest-jasmine2/src/types.ts b/packages/jest-jasmine2/src/types.ts index 4d0ff244005e..5e980f6b09f0 100644 --- a/packages/jest-jasmine2/src/types.ts +++ b/packages/jest-jasmine2/src/types.ts @@ -74,7 +74,6 @@ type JasmineMatcher = { export type JasmineMatchersObject = {[id: string]: JasmineMatcher}; export type Jasmine = { - _DEFAULT_TIMEOUT_INTERVAL: number; DEFAULT_TIMEOUT_INTERVAL: number; currentEnv_: ReturnType['prototype']; getEnv: () => ReturnType['prototype']; diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 8640b45ea405..13cd14cbb242 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -1926,12 +1926,8 @@ export default class Runtime { const spyOn = this._moduleMocker.spyOn.bind(this._moduleMocker); const setTimeout = (timeout: number) => { - if (this._environment.global.jasmine) { - this._environment.global.jasmine._DEFAULT_TIMEOUT_INTERVAL = timeout; - } else { - // @ts-expect-error: https://github.com/Microsoft/TypeScript/issues/24587 - this._environment.global[testTimeoutSymbol] = timeout; - } + // @ts-expect-error: https://github.com/Microsoft/TypeScript/issues/24587 + this._environment.global[testTimeoutSymbol] = timeout; return jestObject; }; From 4d175b4ef92655122b82d777ee4e40c2db928428 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Mon, 6 Dec 2021 10:03:19 +0200 Subject: [PATCH 2/7] use getter and setter --- packages/jest-jasmine2/src/index.ts | 8 ++------ packages/jest-jasmine2/src/jasmine/Env.ts | 12 +++++------- packages/jest-jasmine2/src/jasmine/jasmineLight.ts | 13 ++++++++++++- packages/jest-jasmine2/src/types.ts | 1 + 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/packages/jest-jasmine2/src/index.ts b/packages/jest-jasmine2/src/index.ts index 7db6e8cdd340..efd1b01c30ec 100644 --- a/packages/jest-jasmine2/src/index.ts +++ b/packages/jest-jasmine2/src/index.ts @@ -23,8 +23,6 @@ const JASMINE = require.resolve('./jasmine/jasmineLight'); const jestEachBuildDir = path.dirname(require.resolve('jest-each')); -const testTimeoutSymbol = Symbol.for('TEST_TIMEOUT_SYMBOL'); - export default async function jasmine2( globalConfig: Config.GlobalConfig, config: Config.ProjectConfig, @@ -132,12 +130,10 @@ export default async function jasmine2( configurable: true, enumerable: true, get() { - // @ts-expect-error: https://github.com/Microsoft/TypeScript/issues/24587 - return environment.global[testTimeoutSymbol]; + return this._DEFAULT_TIMEOUT_INTERVAL; }, set(value) { - // @ts-expect-error: https://github.com/Microsoft/TypeScript/issues/24587 - environment.global[testTimeoutSymbol] = value; + this._DEFAULT_TIMEOUT_INTERVAL = value; }, }); } diff --git a/packages/jest-jasmine2/src/jasmine/Env.ts b/packages/jest-jasmine2/src/jasmine/Env.ts index 079b9c1fd974..20975e1e9550 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.ts +++ b/packages/jest-jasmine2/src/jasmine/Env.ts @@ -49,8 +49,6 @@ import type { import type {default as Spec, SpecResult} from './Spec'; import type Suite from './Suite'; -const testTimeoutSymbol = Symbol.for('TEST_TIMEOUT_SYMBOL'); - export default function (j$: Jasmine) { return class Env { specFilter: (spec: Spec) => boolean; @@ -512,7 +510,7 @@ export default function (j$: Jasmine) { queueableFn: { fn, timeout() { - return timeout || (global as any)[testTimeoutSymbol]; + return timeout || j$._DEFAULT_TIMEOUT_INTERVAL; }, }, throwOnExpectationFailure, @@ -624,7 +622,7 @@ export default function (j$: Jasmine) { currentDeclarationSuite.beforeEach({ fn: beforeEachFunction, timeout() { - return timeout || (global as any)[testTimeoutSymbol]; + return timeout || j$._DEFAULT_TIMEOUT_INTERVAL; }, }); }; @@ -633,7 +631,7 @@ export default function (j$: Jasmine) { currentDeclarationSuite.beforeAll({ fn: beforeAllFunction, timeout() { - return timeout || (global as any)[testTimeoutSymbol]; + return timeout || j$._DEFAULT_TIMEOUT_INTERVAL; }, }); }; @@ -642,7 +640,7 @@ export default function (j$: Jasmine) { currentDeclarationSuite.afterEach({ fn: afterEachFunction, timeout() { - return timeout || (global as any)[testTimeoutSymbol]; + return timeout || j$._DEFAULT_TIMEOUT_INTERVAL; }, }); }; @@ -651,7 +649,7 @@ export default function (j$: Jasmine) { currentDeclarationSuite.afterAll({ fn: afterAllFunction, timeout() { - return timeout || (global as any)[testTimeoutSymbol]; + return timeout || j$._DEFAULT_TIMEOUT_INTERVAL; }, }); }; diff --git a/packages/jest-jasmine2/src/jasmine/jasmineLight.ts b/packages/jest-jasmine2/src/jasmine/jasmineLight.ts index 1c25c06100df..be334b91531a 100644 --- a/packages/jest-jasmine2/src/jasmine/jasmineLight.ts +++ b/packages/jest-jasmine2/src/jasmine/jasmineLight.ts @@ -45,7 +45,18 @@ const testTimeoutSymbol = Symbol.for('TEST_TIMEOUT_SYMBOL'); export const create = function (createOptions: Record): Jasmine { const j$ = {...createOptions} as Jasmine; - (global as any)[testTimeoutSymbol] = createOptions.testTimeout || 5000; + Object.defineProperty(j$, '_DEFAULT_TIMEOUT_INTERVAL', { + configurable: true, + enumerable: true, + get() { + return ( + (global as any)[testTimeoutSymbol] || createOptions.testTimeout || 5000 + ); + }, + set(value) { + (global as any)[testTimeoutSymbol] = value; + }, + }); j$.getEnv = function () { const env = (j$.currentEnv_ = j$.currentEnv_ || new j$.Env()); diff --git a/packages/jest-jasmine2/src/types.ts b/packages/jest-jasmine2/src/types.ts index 5e980f6b09f0..4d0ff244005e 100644 --- a/packages/jest-jasmine2/src/types.ts +++ b/packages/jest-jasmine2/src/types.ts @@ -74,6 +74,7 @@ type JasmineMatcher = { export type JasmineMatchersObject = {[id: string]: JasmineMatcher}; export type Jasmine = { + _DEFAULT_TIMEOUT_INTERVAL: number; DEFAULT_TIMEOUT_INTERVAL: number; currentEnv_: ReturnType['prototype']; getEnv: () => ReturnType['prototype']; From 507aa0fb3ce8ae77a6f248cfddfbb6868b3e0b7e Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Mon, 6 Dec 2021 11:33:08 +0200 Subject: [PATCH 3/7] fix: remove `jasmine` types --- packages/jest-jasmine2/src/errorOnPrivate.ts | 36 ++++++------------- .../jest-jasmine2/src/jasmineAsyncInstall.ts | 2 +- packages/jest-jasmine2/src/jestExpect.ts | 7 ++-- .../jest-jasmine2/src/setup_jest_globals.ts | 9 ++--- packages/jest-jasmine2/src/types.ts | 9 +++++ packages/jest-types/src/Global.ts | 11 ------ 6 files changed, 26 insertions(+), 48 deletions(-) diff --git a/packages/jest-jasmine2/src/errorOnPrivate.ts b/packages/jest-jasmine2/src/errorOnPrivate.ts index 1ffe1f0d081c..f8f74788542a 100644 --- a/packages/jest-jasmine2/src/errorOnPrivate.ts +++ b/packages/jest-jasmine2/src/errorOnPrivate.ts @@ -7,29 +7,17 @@ import type {Global} from '@jest/types'; import {ErrorWithStack} from 'jest-util'; -import type {Jasmine} from './types'; - -type DisabledGlobalKeys = 'fail' | 'pending' | 'spyOn' | 'spyOnProperty'; // prettier-ignore -const disabledGlobals: Record = { +const disabledGlobals: Record = { fail: 'Illegal usage of global `fail`, prefer throwing an error, or the `done.fail` callback.', pending: 'Illegal usage of global `pending`, prefer explicitly skipping a test using `test.skip`', spyOn: 'Illegal usage of global `spyOn`, prefer `jest.spyOn`.', spyOnProperty: 'Illegal usage of global `spyOnProperty`, prefer `jest.spyOn`.', }; -type DisabledJasmineMethodsKeys = - | 'addMatchers' - | 'any' - | 'anything' - | 'arrayContaining' - | 'createSpy' - | 'objectContaining' - | 'stringMatching'; - // prettier-ignore -const disabledJasmineMethods: Record = { +const disabledJasmineMethods: Record = { addMatchers: 'Illegal usage of `jasmine.addMatchers`, prefer `expect.extends`.', any: 'Illegal usage of `jasmine.any`, prefer `expect.any`.', anything: 'Illegal usage of `jasmine.anything`, prefer `expect.anything`.', @@ -40,21 +28,19 @@ const disabledJasmineMethods: Record = { }; export function installErrorOnPrivate(global: Global.Global): void { - const jasmine = global.jasmine as Jasmine; + const jasmine = global.jasmine; - (Object.keys(disabledGlobals) as Array).forEach( - functionName => { - global[functionName] = () => { - throwAtFunction(disabledGlobals[functionName], global[functionName]); - }; - }, - ); + Object.keys(disabledGlobals).forEach(functionName => { + global[functionName] = () => { + // @ts-expect-error + throwAtFunction(disabledGlobals[functionName], global[functionName]); + }; + }); - ( - Object.keys(disabledJasmineMethods) as Array - ).forEach(methodName => { + Object.keys(disabledJasmineMethods).forEach(methodName => { // @ts-expect-error jasmine[methodName] = () => { + // @ts-expect-error throwAtFunction(disabledJasmineMethods[methodName], jasmine[methodName]); }; }); diff --git a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts index 84836e81dba4..8adaf78dbc5a 100644 --- a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts +++ b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts @@ -230,7 +230,7 @@ export default function jasmineAsyncInstall( globalConfig: Config.GlobalConfig, global: Global.Global, ): void { - const jasmine = global.jasmine as Jasmine; + const jasmine = global.jasmine; const mutex = throat(globalConfig.maxConcurrency); const env = jasmine.getEnv(); diff --git a/packages/jest-jasmine2/src/jestExpect.ts b/packages/jest-jasmine2/src/jestExpect.ts index 6b586a2fbeb2..2b55ed618160 100644 --- a/packages/jest-jasmine2/src/jestExpect.ts +++ b/packages/jest-jasmine2/src/jestExpect.ts @@ -7,7 +7,6 @@ /* eslint-disable local/prefer-spread-eventually */ -import type {Global} from '@jest/types'; import expect = require('expect'); import { addSerializer, @@ -16,9 +15,7 @@ import { toThrowErrorMatchingInlineSnapshot, toThrowErrorMatchingSnapshot, } from 'jest-snapshot'; -import type {Jasmine, JasmineMatchersObject, RawMatcherFn} from './types'; - -declare const global: Global.Global; +import type {JasmineMatchersObject, RawMatcherFn} from './types'; export default (config: {expand: boolean}): void => { global.expect = expect; @@ -31,7 +28,7 @@ export default (config: {expand: boolean}): void => { }); expect.addSnapshotSerializer = addSerializer; - const jasmine = global.jasmine as Jasmine; + const jasmine = global.jasmine; jasmine.anything = expect.anything; jasmine.any = expect.any; jasmine.objectContaining = expect.objectContaining; diff --git a/packages/jest-jasmine2/src/setup_jest_globals.ts b/packages/jest-jasmine2/src/setup_jest_globals.ts index 7fc6329aa317..5a275d66c36c 100644 --- a/packages/jest-jasmine2/src/setup_jest_globals.ts +++ b/packages/jest-jasmine2/src/setup_jest_globals.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import type {Config, Global} from '@jest/types'; +import type {Config} from '@jest/types'; import {extractExpectedAssertionsErrors, getState, setState} from 'expect'; import { SnapshotState, @@ -19,9 +19,6 @@ import type { default as JasmineSpec, SpecResult, } from './jasmine/Spec'; -import type {Jasmine} from './types'; - -declare const global: Global.Global; export type SetupOptions = { config: Config.ProjectConfig; @@ -67,7 +64,7 @@ const addAssertionErrors = (result: SpecResult) => { }; const patchJasmine = () => { - (global.jasmine as Jasmine).Spec = (realSpec => { + global.jasmine.Spec = (realSpec => { class Spec extends realSpec { constructor(attr: Attributes) { const resultCallback = attr.resultCallback; @@ -86,7 +83,7 @@ const patchJasmine = () => { } return Spec; - })((global.jasmine as Jasmine).Spec); + })(global.jasmine.Spec); }; export default async ({ diff --git a/packages/jest-jasmine2/src/types.ts b/packages/jest-jasmine2/src/types.ts index 4d0ff244005e..c0e0bb1ba415 100644 --- a/packages/jest-jasmine2/src/types.ts +++ b/packages/jest-jasmine2/src/types.ts @@ -96,6 +96,15 @@ declare global { namespace NodeJS { interface Global { expect: typeof expect; + jasmine: Jasmine; + } + } +} + +declare module '@jest/types' { + namespace Global { + interface GlobalAdditions { + jasmine: Jasmine; } } } diff --git a/packages/jest-types/src/Global.ts b/packages/jest-types/src/Global.ts index 010624038707..0d7f4a911642 100644 --- a/packages/jest-types/src/Global.ts +++ b/packages/jest-types/src/Global.ts @@ -51,12 +51,6 @@ export type EachTestFn = ( ...args: Array ) => ReturnType; -// TODO: Get rid of this at some point -type Jasmine = { - _DEFAULT_TIMEOUT_INTERVAL?: number; - addMatchers: (matchers: Record) => void; -}; - type Each = | (( table: EachTable, @@ -124,11 +118,6 @@ export interface TestFrameworkGlobals { export interface GlobalAdditions extends TestFrameworkGlobals { __coverage__: CoverageMapData; - jasmine: Jasmine; - fail: () => void; - pending: () => void; - spyOn: () => void; - spyOnProperty: () => void; } export interface Global From f0ebc2b0bac2116902758906d9873824a13ec8bb Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Mon, 6 Dec 2021 11:55:30 +0200 Subject: [PATCH 4/7] add change log record --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aee1baba6b6..d4a02c24173f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixes - `[babel-jest]` Add `process.version` chunk to the cache key ([#12122](https://github.com/facebook/jest/pull/12122)) +- `[jest-jasmine2, jest-types]` Move all `jasmine` specific types from `@jest/types` to its own package ([#12125](https://github.com/facebook/jest/pull/12125)) ### Chore & Maintenance From acefe11a0b50bc436e570805546e8d9e9a03222b Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Thu, 10 Feb 2022 17:34:01 +0200 Subject: [PATCH 5/7] clean up --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92f57f2c851e..df981d065cf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,6 @@ ### Fixes -- `[babel-jest]` Add `process.version` chunk to the cache key ([#12122](https://github.com/facebook/jest/pull/12122)) - `[expect]` Move typings of `.not`, `.rejects` and `.resolves` modifiers outside of `Matchers` interface ([#12346](https://github.com/facebook/jest/pull/12346)) - `[jest-phabricator]` [**BREAKING**] Convert to ESM ([#12341](https://github.com/facebook/jest/pull/12341)) From a0cb3b0511ecc87506ea2e7e3252f0c5ccb34eb7 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Thu, 10 Feb 2022 17:52:57 +0200 Subject: [PATCH 6/7] add missign methods --- packages/jest-jasmine2/src/types.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/jest-jasmine2/src/types.ts b/packages/jest-jasmine2/src/types.ts index c96c8d789c1d..2d8282a4be6b 100644 --- a/packages/jest-jasmine2/src/types.ts +++ b/packages/jest-jasmine2/src/types.ts @@ -105,6 +105,10 @@ declare module '@jest/types' { namespace Global { interface GlobalAdditions { jasmine: Jasmine; + fail: () => void; + pending: () => void; + spyOn: () => void; + spyOnProperty: () => void; } } } From 946b73578ee17076b8a22060ec70ee2de989fb35 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Thu, 10 Feb 2022 18:05:43 +0200 Subject: [PATCH 7/7] revert type casting --- packages/jest-jasmine2/src/errorOnPrivate.ts | 33 ++++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/packages/jest-jasmine2/src/errorOnPrivate.ts b/packages/jest-jasmine2/src/errorOnPrivate.ts index f8f74788542a..56874b058de4 100644 --- a/packages/jest-jasmine2/src/errorOnPrivate.ts +++ b/packages/jest-jasmine2/src/errorOnPrivate.ts @@ -8,16 +8,27 @@ import type {Global} from '@jest/types'; import {ErrorWithStack} from 'jest-util'; +type DisabledGlobalKeys = 'fail' | 'pending' | 'spyOn' | 'spyOnProperty'; + // prettier-ignore -const disabledGlobals: Record = { +const disabledGlobals: Record = { fail: 'Illegal usage of global `fail`, prefer throwing an error, or the `done.fail` callback.', pending: 'Illegal usage of global `pending`, prefer explicitly skipping a test using `test.skip`', spyOn: 'Illegal usage of global `spyOn`, prefer `jest.spyOn`.', spyOnProperty: 'Illegal usage of global `spyOnProperty`, prefer `jest.spyOn`.', }; +type DisabledJasmineMethodsKeys = + | 'addMatchers' + | 'any' + | 'anything' + | 'arrayContaining' + | 'createSpy' + | 'objectContaining' + | 'stringMatching'; + // prettier-ignore -const disabledJasmineMethods: Record = { +const disabledJasmineMethods: Record = { addMatchers: 'Illegal usage of `jasmine.addMatchers`, prefer `expect.extends`.', any: 'Illegal usage of `jasmine.any`, prefer `expect.any`.', anything: 'Illegal usage of `jasmine.anything`, prefer `expect.anything`.', @@ -30,17 +41,19 @@ const disabledJasmineMethods: Record = { export function installErrorOnPrivate(global: Global.Global): void { const jasmine = global.jasmine; - Object.keys(disabledGlobals).forEach(functionName => { - global[functionName] = () => { - // @ts-expect-error - throwAtFunction(disabledGlobals[functionName], global[functionName]); - }; - }); + (Object.keys(disabledGlobals) as Array).forEach( + functionName => { + global[functionName] = () => { + throwAtFunction(disabledGlobals[functionName], global[functionName]); + }; + }, + ); - Object.keys(disabledJasmineMethods).forEach(methodName => { + ( + Object.keys(disabledJasmineMethods) as Array + ).forEach(methodName => { // @ts-expect-error jasmine[methodName] = () => { - // @ts-expect-error throwAtFunction(disabledJasmineMethods[methodName], jasmine[methodName]); }; });