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
We are encountering difficulties when attempting to mock methods that are defined inside existing class properties. The nested property is automatically overwritten with a mocked object, so the actual method inside the property we need to mock is undefined and cannot be accessed (and cannot be mocked, basically).
Steps to reproduce
Define a class with a property that contains a method. e.g.:
classOtherClass{publicgetSomething: ()=>string}
classMyClass{readonlyproperty: OtherClass}
. Attempt to mock MyClass
letmyClass: jest.Mocked<MyClass>;const{ unit, unitRef }=TestBed.create(ServiceUnderTest).mock(MyClass).using({property: {getSomething: jest.fn()}}).compile();myClass=unitRef.get(MyClass)
In the actual test try to mock resolved value getSomething, e.g:
The method inside the class property should be successfully mocked. In the above example trying to do .getSomething.mockResolvedValue Should not throw an error - getSomething is undefined
Automock version
v2.1.0
The text was updated successfully, but these errors were encountered:
omermorad
changed the title
mock().using does not work on method nested inside class propertry
mock().using does not work on method nested inside class property [@automock]
Jul 13, 2024
Is there an existing issue for this?
Current behavior
We are encountering difficulties when attempting to mock methods that are defined inside existing class properties. The nested property is automatically overwritten with a mocked object, so the actual method inside the property we need to mock is undefined and cannot be accessed (and cannot be mocked, basically).
Steps to reproduce
MyClass
myClass.property.getSomething.mockResolvedValue('mocked')
Expected behavior
The method inside the class property should be successfully mocked. In the above example trying to do
.getSomething.mockResolvedValue
Should not throw an error - getSomething is undefinedAutomock version
v2.1.0
The text was updated successfully, but these errors were encountered: