I'm attempting to mock the Uppy
class from the uppy package in a Jest unit test following guidance from this previously answered question. My failing code is below:
import Uppy from '@uppy/core';
describe('MyComponent', () => {
it('renders', () => {
jest.mock('@uppy/core', () => {
return {
Uppy: jest.fn().mockImplementation(() => {
return {};
}),
};
});
new Uppy();
expect(Uppy).toHaveBeenCalledTimes(1);
});
});
The test fails with the following error message:
Matcher error: received value must be a mock or spy function
Received has type: function
Received has value: [Function Uppy]
It appears that the default export from @uppy/core
is the Uppy
class, so my expectation is that the provided code would mock the class' constructor, however this doesn't seem to be the case.
Package versions:
- Uppy: 2.1.2
- Jest: 27.4.7