casesandberg / casesandberg/react-color

I cannot mock SketchPicker using jest

Open
#745 0 comments 0 reactions 0 assignees View on GitHub
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();
});
});
```

![Screenshot 2020-08-14 at 13 20 44](https://user-images.githubusercontent.com/8180548/90240052-3a3c1000-de31-11ea-89c2-3a676bf11aca.png)

The error does not come up if I remove the mock implementation.

Contributor guide

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.