diff --git a/CHANGELOG.md b/CHANGELOG.md index f2f972043922..052492261ef8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ - `[jest-changed-files]` Fix a lock-up after repeated invocations ([#12757](https://github.com/facebook/jest/issues/12757)) - `[@jest/expect-utils]` Fix deep equality of ImmutableJS OrderedSets ([#12977](https://github.com/facebook/jest/pull/12977)) -- `[jest-mock]` Add index signature support for `spyOn` types ([#13013](https://github.com/facebook/jest/pull/13013)) +- `[jest-mock]` Add index signature support for `spyOn` types ([#13013](https://github.com/facebook/jest/pull/13013), [#13020](https://github.com/facebook/jest/pull/13020)) - `[jest-snapshot]` Fix indentation of awaited inline snapshots ([#12986](https://github.com/facebook/jest/pull/12986)) ### Chore & Maintenance diff --git a/packages/jest-mock/__typetests__/mock-functions.test.ts b/packages/jest-mock/__typetests__/mock-functions.test.ts index daf115d5bf52..6a7d6b82d0b6 100644 --- a/packages/jest-mock/__typetests__/mock-functions.test.ts +++ b/packages/jest-mock/__typetests__/mock-functions.test.ts @@ -374,8 +374,6 @@ expectType>( spyOn(indexSpiedObject, 'methodE'), ); -expectError(spyOn(indexSpiedObject, 'propertyA')); - expectType {a: string}>>( spyOn(indexSpiedObject, 'propertyA', 'get'), ); diff --git a/packages/jest-mock/__typetests__/utility-types.test.ts b/packages/jest-mock/__typetests__/utility-types.test.ts index 2faa5521d4ce..1a991b0b4d5b 100644 --- a/packages/jest-mock/__typetests__/utility-types.test.ts +++ b/packages/jest-mock/__typetests__/utility-types.test.ts @@ -86,10 +86,10 @@ type IndexObject = { methodA(): void; methodB(b: string): boolean; - methodC: (c: number) => true; + methodC: (c: number) => boolean; - propertyA: {a: 123}; - propertyB: {b: 'value'}; + propertyA: {a: number}; + propertyB: {b: string}; }; // ClassLike @@ -142,6 +142,6 @@ declare const objectProperties: PropertyLikeKeys; declare const indexObjectProperties: PropertyLikeKeys; expectType<'propertyA' | 'propertyB' | 'propertyC'>(classProperties); -expectType(indexClassProperties); +expectType(indexClassProperties); expectType<'propertyA' | 'propertyB' | 'someClassInstance'>(objectProperties); -expectType(indexObjectProperties); +expectType(indexObjectProperties); diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index 283e06b1920d..af36d752bf70 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -42,13 +42,10 @@ export type MethodLikeKeys = keyof { [K in keyof T as T[K] extends FunctionLike ? K : never]: T[K]; }; -export type PropertyLikeKeys = { - [K in keyof T]: T[K] extends FunctionLike - ? never - : T[K] extends ClassLike - ? never - : K; -}[keyof T]; +export type PropertyLikeKeys = Exclude< + keyof T, + ConstructorLikeKeys | MethodLikeKeys +>; // TODO Figure out how to replace this with TS ConstructorParameters utility type // https://www.typescriptlang.org/docs/handbook/utility-types.html#constructorparameterstype