我使用的解决方案是将ref传递给滑块,将间谍传递给afterChange方法,但没有调用它。
it('should update local value on top slider move',() => {
// I use 2 sliders
const [top,main]: Array<RefObject<SliderMethods>> = [
React.createRef(),React.createRef(),];
const indexes = { main: 0,top: 1 };
const afterChange = type => {
return index => {
indexes[type] = index;
};
};
const {
container,} = render(<Component sliderRefs={[top,main]} afterChange={afterChange} />);
top.current!.slickNext();
console.log(indexes); // it did not change
});