Suggestion for more accurate types for nested objects
fixes #885
export class MyClass {
foo = {
bar: () => {
return 'foo.bar';
},
};
}
test('foo.bar', () => {
const myMock = createMock<MyClass>();
myMock.foo.bar.mockResolvedValue('foo.bar');
});
Based off the createMock source this nested object should also be a mock. Updating the typings as suggested fix this.
There are very likely other spots that need to be fixed too, I just looked at this specific error for now, if this is a good change I can look at the rest and add them to the PR.
@NickBolles Are you able to add test coverage to fully expose this case? I'm trying to see which more scenarios this would capture and whether it may introduce hotspots to the typescript compiler
Would love to see this improvement too since we know the mock exists but currently are working around it with code like -
(dbService.table.findAll as jest.Mock).mockResolvedValueOnce(data)
LMK if anything can be done to help.
@NickBolles Are you able to provide some test coverage?
@NickBolles Sorry for bumping, are you still maintaining the draft?