我无法在我的反应原生组件中使用 jest 测试包含去抖动功能的方法。有人可以帮我弄这个吗?
下面的代码是我试图开玩笑地测试我的去抖功能,但它没有工作。
jest.mock('lodash/debounce', () => jest.fn(fn => fn));
it('should test debounce function', () => {
debounce.mockClear();
expect(debounce).toHaveBeenCalledTimes(1);
});
下面的代码片段是我的方法,其中包含我正在尝试测试的 lodash 的 debounce 函数。
import { debounce } from 'lodash';
private getSearchConnections = debounce(() => {
this.props.searchConnections(this.state.query, 1, false);
}, 100
);