mocked() no longer seems to function correctly
See original GitHub issueI’m sort of surprised nobody else has encountered this, but I’m seeing it in two repos with quite different setups.
Issue
As of the latest Jest / ts-jest and @types/jest, any test runs throw errors for mock properties not existing on MockedFunction<>
. For example:
error TS2339: Property 'mockRejectedValue' does not exist on type 'MockedFunction<RequestAPI<RequestPromise<any>, RequestPromiseOptions, RequiredUriUrl>>'.
29 requestMock.mockRejectedValue(new Error());
The setup itself is very very simple;
import { mocked } from 'ts-jest/utils';
jest.mock('request-promise-native');
import * as request from 'request-promise-native';
const requestMock = mocked(request);
afterEach(() => requestMock.mockRestore());
This looks like it might be similar to https://github.com/kulshekhar/ts-jest/issues/991
Expected behavior
mocked()
works as in ts-jest 23.x
Issue Analytics
- State:
- Created 5 years ago
- Reactions:25
- Comments:15 (3 by maintainers)
Top Results From Across the Web
Mockito when method not working - Stack Overflow
Mockito mock works when we mock the objects loosely. Here is the change i have made to make it work: when(controlWfDefTypeService.
Read more >The only 3 steps you need to mock an API call in Jest
We're going to be testing this getFirstAlbumTitle() function, ... a function imported into your test – Jest will mock the function no matter ......
Read more >Why your mock doesn't work - Ned Batchelder
Mocking is a powerful technique for isolating tests. But yours isn't working. Why!?
Read more >Mocking functions in Python with Pytest Part I - FreBlogg
I am operating with the assumption that you can write unit tests in Python using pytest . Why Mock? As you are here,...
Read more >Mocks failing to work correctly in large test runs? - Telerik
They seem to be failing because mocks are not correctly ... Fill(), but in stead of mocking the method, it executes the real...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m in the process of merging 994 in. Unfortunately ts-jest is in a bit of a twilight zone right now, as none of the core maintainers have very much time to dedicate to it. We’re doing our best, but response times are probably going to be pretty slow until someone has more free time (or another contributor steps up to the plate)
Thanks for being polite about it.
Hey @GeeWee,
Any chance you or one of the other maintainers can review this? It’s been over a month, and your current release is broken / unusable.
If the library isn’t being maintained any more, that’s okay! Happy to fork, I don’t expect free work, but a quick yes / no would be wonderful.
Thanks