-
Notifications
You must be signed in to change notification settings - Fork 455
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
Feature req: Add static functions for mock functions. #661
Comments
Thanks @TKJohn. The easiest workaround is to put you Also check https://github.com/kulshekhar/ts-jest/wiki/Troubleshooting#jestmock-hoisting. I have no time to investigate more right now sorry. In case what I quickly gave you here fixes your bug, thanks for closing this issue. |
Thanks @huafu. And sorry for my misleading. It is not a bug, the test works well as expect. Mocks works fine. Not the case in the trouble shooting. The only problem is the IDE(as well TS) complain about 'mockImplementation' is not defined in the (actually mocked) function. Tested putting jest.mock('xxx') call before the actual import ... from 'xxx' in the test file, but doesn't make different. |
oh ok, i misunderstood sorry. There is already an issue for this, it's typings for mock or so. It's a won't fix for now. Can't search for the issue now, but there is more info related to that in there, you should look for it. |
Found out #576. And it is a good hint to use type case to deal with type issus. |
Issue :
When mocking module by jest.mock(), I would like to use jest.fn() to mock functions of the module.
Latter in the actual tests, I need to implement different behavior for the functions.
The mock functions works fine with JS. But in TypeScript, with
dependencyFunc
has no definedmockImplementation
, the IDE(vscode) shows errorThe test can still run successfully. But I think it would be better to have some global functions to do the implement. Likes
when
in mockito.Expected behavior :
I would suggest to add global/static functions for mock functions. Something could be used like:
Output from debug log :
# content of debug.txt : none
Minimal repo :
https://github.com/TKJohn/ut-ts-jest
https://github.com/TKJohn/ut-ts-jest/blob/master/test/dependent-modify.spec.ts
The text was updated successfully, but these errors were encountered: