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
[jest] Add mock functions for v22 #1918
base: master
Are you sure you want to change the base?
Conversation
There are test errors:
But I don't have a good idea to fix them... Any idea ? |
Test suite seems to take diff for grandparent instead of parent: #1920 |
Restarting build... |
Oh, sorry i totally misread the errors. They seems to come from Jest, not from unrelated libdefs. So rebasing in this case doesn't help. |
Yep totally, the error definitely comes from my typing :-) I don't understand why the typing doesn't yield these errors and were seeking for some help. |
@julienw Could you still try rebasing this PR on the latest version of master? |
690a542
to
abd049d
Compare
Oh sure, I just did ! |
Awesome. I just wanted to make sure that the errors were indeed coming from the typings, and that any changes weren't going to fail because of an unrelated issue. |
Ping @gantoine :) Looks like you had something in mind to check, so I'll let you be the one to pull the trigger on the PR. |
@julienw It seems the specs are failing again, and I don't think it's due to any issues in the master branch. When you get a chance, could you take a look at them? |
Yes, actually, that's what I said in #1918 (comment) :) I don't know how to fix these problems and I'd like some help here. |
From my test the |
I simplified the problem in try. Maybe the problem is how Flow infers the parameters to |
…RejectedValueOnce to jest mocked functions
beffed4
to
a320fbd
Compare
Looks like the errors are different at least. :) LMK if you're still needing help. |
Yeah, if you can help to find what doesn't work in the try I mentioned above, it would help a lot. We should have errors in that try but we don't have any. I think the problem is how |
Otherwise I can just remove these test cases so that we can land this already. |
Have you tested this in the wild? Does it work there? Otherwise I'd change the type def to not extract the promise value and worry about that, just provide something like |
I think we can't do this. We really want to extract the type because that's what we pass to these functions. Eg if a mock function returns a For example if we were in the Rust world, I could do something like Maybe we can do something similar here, converting JestMockFn to a class or an interface. I use this in the wild. |
I tried it and stumbled on facebook/flow#5437 |
Hm. Seems like we've been spinning our wheels here for a while. I'd be fine with flipping the table and just putting If you're fine going that route, just make sure to link to this conversation and briefly explain how it's essentially impossible right now. |
I see #2396 reused part of this PR to land the feature. I'm a bit surprised that it didn't use |
OK I find that the typings are failing for things like: foo.doAsyncStuff = jest
.fn()
.mockResolvedValueOnce(10)
.mockResolvedValueOnce(42);
foo.doAsyncStuff = jest.fn();
foo.doAsyncStuff.mockRejectedValueOnce(new Error("hello world")); Using a type closer to this PR makes these work, but fail other existing valid and important tests, especially this isn't checked anymore: // $ExpectError Mock function expected to return Promise<number>, not Promise<string>
foo.doAsyncStuff = jest.fn().mockResolvedValue("10"); |
This is my current try: https://github.com/flow-typed/flow-typed/compare/master...julienw:jest-resolved-values-fix?expand=1 Various tests are failing... the 2 I was mentioning above, plus new tests failing in latest 2 flow versions :/ |
Add mockResolvedValue, mockResolvedValueOnce, mockRejectedValue, mockRejectedValueOnce to jest mocked functions