mock javascript function

Solutions on MaxInterview for mock javascript function by the best coders in the world

showing results for - "mock javascript function"
Giada
15 Oct 2020
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