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

ts-jest: regression in 0.5.1 #757

Closed
rbnayax opened this issue Aug 11, 2024 · 0 comments
Closed

ts-jest: regression in 0.5.1 #757

rbnayax opened this issue Aug 11, 2024 · 0 comments

Comments

@rbnayax
Copy link
Contributor

rbnayax commented Aug 11, 2024

version 0.5.1 introduced a regression that was a result of #752

Mocked implementation that returns bullish values stopped working.

The following test illustrates the issue:

import { createMock } from '@golevelup/ts-jest';

describe(`test`, () => {
  it('mock called with another mock', async () => {
    interface Test {
      foo(): number | undefined;
    }

    const mock = createMock<Test>();
    mock.foo.mockImplementation(() => {
      return 6;
    });
    expect(mock.foo()).toEqual(6);
    mock.foo.mockImplementation(() => {
      return 7;
    });
    expect(mock.foo()).toEqual(7);
    mock.foo.mockImplementation(() => {
      return 0;
    });
    expect(mock.foo()).toEqual(0); // Fails
    mock.foo.mockImplementation(() => {
      return undefined;
    });
    expect(mock.foo()).toEqual(undefined); //Fails
  });
});
Error: Unexpected return from a matcher function.
Matcher functions should return an object in the following format:
  {message?: string | function, pass: boolean}
'{"actual": [Function mockConstructor], "expected": 0, "message": [Function anonymous], "name": "toEqual", "pass": [Function mockConstructor]}' was returned
VonRehberg pushed a commit to VonRehberg/nestjs that referenced this issue Aug 11, 2024
underfisk added a commit that referenced this issue Sep 16, 2024
* fix(ts-jest): fixed nullable mocks issue

closes #757

* fix: allow boolean return values in mocks closes #778

---------

Co-authored-by: Christian Jeschke <cjeschke@vonrehberg.consulting>
Co-authored-by: Rodrigo <monstawoodwow@gmail.com>
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 a pull request may close this issue.

1 participant