-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Bug]: "mockImplementation" is behaving different than the syntacical-sugar version"mockResolvedValue" #13206
Comments
I can now confirm it has to do with #6645 : const testMock = {
works: jest.fn().mockImplementation(() => Promise.resolve(undefined)),
fails: jest.fn().mockResolvedValue(undefined),
};
it('test-mockImplementation', fakeAsync(async() => {
console.log(new Promise(() => null) instanceof Promise); // true
console.log(testMock.works() instanceof Promise); // true
console.log(testMock.fails() instanceof Promise); // FALSE
expect(true).toBeTrue();
})); The |
Any chance this issue will be verified and tackled? It's an easy reproducible bug which should be also somewhat-eaasy to fix. |
I confirm this should be fixed. For example, waiting for a next tick would finish the promises with mockImplementation but not with mockResolved or mockReject. |
Reproductions here give me A full standalone reproduction would allow me to verify if #13503 fixed the reported issue. You can also probably just make the change I made there in your own |
@mhombach please give https://github.com/facebook/jest/releases/tag/v29.2.2 a try 🙂 |
@SimenB big thanks, will test tomorrow and report back :) |
Update: Following a longer discussion on this issue: #6645 The #6645 tried to fix the problem, but (to my impression) failed to do so. It added this unit-test (https://github.com/SimenB/jest/blob/464b45a015f98485d4037f1b4d4c5da750e39890/e2e/mock-functions/__tests__/index.js) to make sure that test('instanceof promise', async () => {
const resolvedPromise = jest.fn().mockResolvedValue('hello')();
const rejectedPromise = jest.fn().mockRejectedValue('hello')();
expect(resolvedPromise).toBeInstanceOf(Promise);
expect(rejectedPromise).toBeInstanceOf(Promise);
await expect(resolvedPromise).resolves.toBe('hello');
await expect(rejectedPromise).rejects.toBe('hello');
}); This is the code written in the unit test in #6645 . Also, if we do a
@SimenB maybe we can continue our discussion here? I think I have provided sufficient evidence and explained my case in detail. A minimum repro would be: test('instanceof promise', async () => {
const resolvedPromise = jest.fn().mockResolvedValue('hello')();
const rejectedPromise = jest.fn().mockRejectedValue('hello')();
expect(resolvedPromise).not.toBeInstanceOf(Promise);
expect(rejectedPromise).not.toBeInstanceOf(Promise);
console.log(resolvedPromise instanceof Promise);
console.log(rejectedPromise instanceof Promise);
await expect(resolvedPromise).resolves.toBe('hello');
await expect(rejectedPromise).rejects.toBe('hello');
}); |
@SimenB any feedback on this? Again, my assumption is that the fix you implemented does not work and the unit tests added are not passing and just silently erroring out. |
Issue is still not fixed |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Issue is not fixed yet |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Issue is not fixed yet |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Issue is not fixed yet |
@SimenB any chance you can have a look at this again? See my last comment here where I provided more insights. thx |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Issue still needs a fix. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Issue is not fixed yet. Seriously, this issue is now open for almost 1 full year and it's ignored? |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
@SimenB Almost 1 year has passed and there is no response or feedback regarding this issue. Could you at least explain why this bug, which isn't affecting only me and is hard to debug/find (as others here can confirm), is not even looked at by you or others? :/ |
Can you proof that? |
@mrazauskas |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Issue is not fixed yet |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
@SimenB could you please have a look at this issue again? It's open for over 1 year now. I provided sffucient evidence that the last "patch" is not working and also a reproduceable example for testing. If this does not fit your needs, then what could a fellow dev possibly do to get a fix for this bug? |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Bug still open, just nobody is accepting this fact. Please archive the repo if you don't intend to fix reported bugs. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Ok I give up. I tried now for almost 2 years to have a serious bug fixed in your worldwide shipped unit-testing code. I provided a vast amount of information, also when you shipped a patch that didn't fix the issue (proven by example, as I explained in full detail). I bumped this issue for eternity, pinging one of the maintainers directly but never got any response. I will stop bumping this thread. For whoever encounters the same initial problem and scrolled all the way to the bottom: Maybe consider using a different, new and modern framework that looks promising. It's not only about this bug, but the way how bugs are explicitly not considered or responded to on this repo. I assume there are all kind of other bugs (as in every code/repo) and if the procedure here shows how bugs are tackled, then jest is just not as reliable as it should. My bug still exists, you will get PASSES for unit tests that should FAIL because of some error, which obviously leads directly to buggy code beeing deployed. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Version
27.5.1
Steps to reproduce
Repro:
Expected behavior
Both tests are passing without any error, since both should be exactly the same as the Jest-docs are stating that
mockFn.mockResolvedValue(value)
is "Syntactic sugar function for"jest.fn().mockImplementation(() => Promise.resolve(value))
.Actual behavior
Test
test-mockResolvedValue
fails on theflush()
due toThe code should be running in the fakeAsync zone to call this function
:Additional context
I feel this problem is linked to #6645 and #11146 .
Environment
The text was updated successfully, but these errors were encountered: