casesandberg / casesandberg/react-color
I cannot mock SketchPicker using jest
- Dominant language
- JavaScript
- Stars
- 12.3k
- Forks
- 920
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to test a component of my own that makes use of Sketch Picker
```
import { SketchPicker } from 'react-color';
jest.mock('react-color');
describe('when color is changed on SketchPicker', () => {
beforeEach(() => {
SketchPicker.mockImplementation((props) => {
this._onChange = props.onChange;
return <>SketchPicker;
});
});
afterEach(() => {
SketchPicker.mockClear();
});
it('should trigger onChange', async () => {
const { getByTestId, debug } = await render();
fireEvent.click(getByTestId('color-picker-current-color'));
debug();
});
});
```

The error does not come up if I remove the mock implementation.
Contributor guide
Research direction
No repository file or project test is named. Start by reproducing the provided Jest test with the SketchPicker mock and compare it with the version without the mock; the issue needs a clearly identified error and expected behavior before completion can be defined.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100