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

fix(ts-sinon): fixed match all issue of jest mocks #752

Merged
merged 1 commit into from
Jun 28, 2024

Conversation

VonRehberg
Copy link
Contributor

This PR fixes issue #703

Copy link
Contributor

@underfisk underfisk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thank you for this addition 🙏

@underfisk underfisk enabled auto-merge (squash) June 28, 2024 13:09
@underfisk underfisk merged commit 9e8fd47 into golevelup:master Jun 28, 2024
3 checks passed
@VonRehberg
Copy link
Contributor Author

Thanks for maintaining these tools and for merging!

I was considering to mark my commit as a breaking change instead of a patch.
In my opinion it fixes an issue, but it could cause a lot of tests to fail in packages using renovate. Please consider this when publishing to npm

@rbnayax
Copy link
Contributor

rbnayax commented Aug 11, 2024

Hi guys, this causes a major regression. For example, we can't use jest-when lib anymore as the returned mock is now a proxy and not jest.fn() and as such we can't set any properties to it.
Please undo this and find a better solution for the issue that initiated this PR.

@rbnayax
Copy link
Contributor

rbnayax commented Aug 11, 2024

The following test passes in 0.5.0, but fails in 0.5.1. Still trying to figure out why it fails.

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

@rbnayax
Copy link
Contributor

rbnayax commented Aug 11, 2024

The new apply trap is causing the issue, working on a fix

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.

None yet

3 participants