📜  模拟 javascript 函数 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:29.906000             🧑  作者: Mango

代码示例1
// ---- comp.js ----
import * as React from 'react';
import * as comp from './comp';

export const remove = () => {
  // ...do something
}

export const RemoveButton = (props) => (
  
comp.remove()}> Remove
); // ---- comp.test.js ---- import * as React from 'react'; import { shallow } from 'enzyme'; import * as comp from './comp'; describe('removeButton', () => { it('should call remove on click', () => { const mock = jest.spyOn(comp, 'remove'); mock.mockImplementation(() => {}); const component = shallow(); component.find('div').simulate('click'); expect(mock).toHaveBeenCalled(); mock.mockRestore(); }); });