Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set mock return value on toString #120

Open
spalladino opened this issue May 22, 2023 · 0 comments
Open

Cannot set mock return value on toString #120

spalladino opened this issue May 22, 2023 · 0 comments

Comments

@spalladino
Copy link

The following fails with a TypeError: foo.toString.mockReturnValue is not a function:

interface Foo {
  toString(): string;
}

const foo = mock<Foo>();
foo.toString.mockReturnValue('bar');

My guess for the issue is that mock uses an empty object as a default first argument, which has the toString default js method, and that causes jest-mock-extended not to generate a jest.fn for it.

FWIW, it can be worked around by just providing a different toString to the default implementation:

const foo = mock<Foo>({
  toString: () => 'bar',
});
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

No branches or pull requests

1 participant