I have a unit test that is using Jasmine to spy on a function and is attempting to return a mocked response.
Both my mock and the real object implement the same interface so that they have the exact same public structure, however the real implementation has private methods to facilitate its work which the mock does not. It doesn't need them.
However it would appear TypeScript considers these not interchangeable and complains that my mock does not implement the private methods. They are private using the private
keyword rather than #
This has started happening since we upgraded from TS v 3 to 4.
Is this by design or is there something a bit squiffy going on here? I've tried looking through migration docs and not found anything.
This is how I spy on my service.
const modalRef = new MockModalRef();
spyOn(modalService, 'open').and.returnValue(modalRef);
This is the actual error TS gives me, all the _
methods it mentions are private fields.
Argument of type 'MockModalRef<any>' is not assignable to parameter of type 'ModalRef<any>'.
Type 'MockModalRef<any>' is missing the following properties from type 'ModalRef<any>': _afterClosed, _beforeClosed, _events, _result, and 6