1// ---- comp.js ----
2import * as React from 'react';
3import * as comp from './comp';
4
5export const remove = () => {
6 // ...do something
7}
8
9export const RemoveButton = (props) => (
10 <div onClick={() => comp.remove()}>
11 Remove
12 </div>
13);
14
15
16// ---- comp.test.js ----
17import * as React from 'react';
18import { shallow } from 'enzyme';
19
20import * as comp from './comp';
21
22describe('removeButton', () => {
23 it('should call remove on click', () => {
24 const mock = jest.spyOn(comp, 'remove');
25 mock.mockImplementation(() => {});
26 const component = shallow(<comp.RemoveButton />);
27 component.find('div').simulate('click');
28 expect(mock).toHaveBeenCalled();
29 mock.mockRestore();
30 });
31});
32