I have a class of service
Service.js
class Service { } export default new Service();
And I'm trying to provide a mock implementation for this. If I use something like this:
jest.mock('./Service', () => { ... my mock stuff });
It works fine, however I cannot access any variables declared outside the layout, which is a bit limiting, since I would like to reconfigure what mock returns, etc.
I tried this (inspired by this other StackOverflow article: Service mocking with Jest reasons "Factory module for jest.mock () is not allowed to refer to any out-of-scope")
import service from './Service'; jest.mock('./Service', () => jest.fn); service.mockImplementation(() => { return { ... mock stuff } );
Unfortunately, when I try to run this, I get the following error:
TypeError: _Service2.default.mockImplementation is not a function
jestjs
Janos
source share