question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mocked() no longer seems to function correctly

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Reactions:25
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
GeeWeecommented, Mar 30, 2019

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.

3reactions
robcresswellcommented, Mar 27, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found