You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
jest.spyOn for getters/setters seems to work correctly with most Types, but breaks with any complex function type.
typeCustomType={hello: string;world: World;}classWorld{innitialize(){console.log('hello');}};classExample{gethello(){return'world';}getworld(): CustomType{return{hello: 'world',world: newWorld(),};}getnativeFunction(): Function{return()=>{};}setnativeFunction(_: Function){// do nothing}getworldFactory(): ()=>()=>World{return()=>()=>newWorld();}setworldFactory(_: ()=>()=>World){// do nothing}}constexample=newExample();jest.spyOn(example,'hello','get').mockReturnValue('mocked');jest.spyOn(example,'world','get').mockReturnValue({hello: 'mocked',world: newWorld()});jest.spyOn(example,'nativeFunction','get').mockReturnValue(jest.fn());jest.spyOn(example,'nativeFunction','set').mockImplementation(jest.fn());jest.spyOn(example,'worldFactory','get').mockReturnValue(()=>()=>newWorld());//----------------------------------^ Argument of type 'string' is not assignable to parameter of type 'never'.jest.spyOn(example,'worldFactory','set').mockImplementation(jest.fn());//----------------------------------^ Argument of type 'string' is not assignable to parameter of type 'never'.
Expected behavior
I expect that all Types should be usable while spying on getters and setters
Actual behavior
complex getters and setters always throw Argument of type 'string' is not assignable to parameter of type 'never'.
or Argument of type '"<getter name>"' is not assignable to parameter of type '"<other>" | "<valid>" | "<getters>"'. (The latter is probably keyOf Type, and the complex getter is somehow excluded from those keys?)
the error is different if you import jest from @jest/globals
import{jest}from'@jest/globals';typeCustomType={hello: string;world: World;}classWorld{innitialize(){console.log('hello');}};classExample{gethello(){return'world';}getworld(): CustomType{return{hello: 'world',world: newWorld(),};}getnativeFunction(): Function{return()=>{};}setnativeFunction(_: Function){// do nothing}getworldFactory(): ()=>()=>World{return()=>()=>newWorld();}setworldFactory(_: ()=>()=>World){// do nothing}}constexample=newExample();jest.spyOn(example,'hello','get').mockReturnValue('mocked');jest.spyOn(example,'world','get').mockReturnValue({hello: 'mocked',world: newWorld()});jest.spyOn(example,'nativeFunction','get').mockReturnValue(jest.fn());jest.spyOn(example,'nativeFunction','set').mockImplementation(jest.fn());jest.spyOn(example,'worldFactory','get').mockReturnValue(()=>()=>newWorld());//------------------^ Argument of type '"worldFactory"' is not assignable to parameter of type '"world" | "hello" | "nativeFunction"'.jest.spyOn(example,'worldFactory','set').mockImplementation(jest.fn());//------------------^ Argument of type '"worldFactory"' is not assignable to parameter of type '"world" | "hello" | "nativeFunction"'.
Environment
System:
OS: macOS 13.4
CPU: (10) arm64 Apple M1 Pro
Binaries:
Node: 18.9.0 - ~/.nvm/versions/node/v18.9.0/bin/node
npm: 8.19.1 - ~/.nvm/versions/node/v18.9.0/bin/npm
The text was updated successfully, but these errors were encountered:
Version
29.1.0
Steps to reproduce
jest.spyOn
for getters/setters seems to work correctly with most Types, but breaks with any complex function type.Expected behavior
I expect that all Types should be usable while spying on getters and setters
Actual behavior
complex getters and setters always throw
Argument of type 'string' is not assignable to parameter of type 'never'.
or
Argument of type '"<getter name>"' is not assignable to parameter of type '"<other>" | "<valid>" | "<getters>"'.
(The latter is probablykeyOf Type
, and the complex getter is somehow excluded from those keys?)Debug log
ts-jest.log
Additional context
the error is different if you import
jest
from@jest/globals
Environment
The text was updated successfully, but these errors were encountered: