Testing debounced method in React with Enzyme
问题 //Component import _ from 'lodash'; constructor(props) { super(props); this.onScroll = _.debounce(::this.onScroll, 100); } onScroll() { //some code } //Test it('onScroll', () => { const component = shallow(<Component />); component.instance().onScroll(); //Dosn't call method }) I use enzyme for render component, and lodash for debounce. How to call component.instance().onScroll() ? 回答1: TL;DR; use lolex to advance in time while mocking timers for testing _.debounce I was ready to describe