Skip to content

Conversation

@NickBolles
Copy link

@NickBolles NickBolles commented Dec 16, 2024

fixes #885

export class MyClass {
  foo = {
    bar: () => {
      return 'foo.bar';
    },
  };
}

test('foo.bar', () => {
  const myMock = createMock<MyClass>();

  myMock.foo.bar.mockResolvedValue('foo.bar');
});
image

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 NickBolles changed the title Suggestion for more accurate types Suggestion for more accurate types for nested objects Dec 16, 2024
@underfisk
Copy link
Collaborator

@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

@JacobSiegle
Copy link
Contributor

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.

@underfisk
Copy link
Collaborator

@NickBolles Are you able to provide some test coverage?

@underfisk
Copy link
Collaborator

@NickBolles Sorry for bumping, are you still maintaining the draft?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested objects aren't typed as DeepMocked

3 participants