How to test react-draggable? Jest + Enzyme
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript, react
- Domain
- frontend, testing-qa
Research direction
Start with the MyComponent shallow-rendering test and the Draggable props shown in the issue, then review the react-draggable event API and the existing test setup. Confirm which interaction handlers are exposed by the rendered wrapper and define a passing test that verifies the relevant callbacks are invoked.
Written by the indexing model from the issue text.
Description
Hello, How to test react-draggable? I try to do it by following code but it is not working (spy is not called):
describe('<MyComponent /> component:', () => {
let wrapper;
const props = {
dragStart: jest.fn(),
dragExit: jest.fn(),
dragMove: jest.fn()
};
beforeEach(() => {
wrapper = shallow(<MyComponent {...props}/>);
});
describe('Interaction:', () => {
it('should call dragStart()', () => {
wrapper.find('Dragabble').simulate('dragStart');
expect(props.dragStart).toHaveBeenCalled(); // FAIL
});
it('should call dragExit()', () => {
wrapper.find('div.bar').simulate('dragExit');
expect(props.dragExit).toHaveBeenCalled(); // FAIL
});
});
});
My draggable component looks like this:
<Draggable
onStart={this.props.dragStart.bind(this)}
onStop={this.props.dragExit.bind(this)}
onDrag={this.props.dragMove.bind(this)}>
(...)
</Draggable>
- Dominant language
- JavaScript
- Stars
- 9.3k
- Forks
- 1k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 4
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from react-grid-layout/react-draggable
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
react-grid-layout/react-draggable#784 · 4 comments · 2 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
react-grid-layout/react-draggable#782 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
react-grid-layout/react-draggable#781 · 1 comment · 2 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
react-grid-layout/react-draggable#780 · 8 comments ·
All issues in react-grid-layout/react-draggable
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
avniproject/avni-client#2135 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
babalae/bettergi-scripts-list#3674 ·
-
A-Release-Notes C-Editing D-Modest S-Ready-For-Implementation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
bevyengine/bevy-website#2595 ·
-
ecosystem wording
Difficulty 1/5 Under an hour Newbie friendliness 90/100
matrix-org/matrix.org#3649 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
vadimdemedes/ink#1029 ·