Javascript 调用jest模拟函数时执行回调

Javascript 调用jest模拟函数时执行回调,javascript,unit-testing,testing,jestjs,Javascript,Unit Testing,Testing,Jestjs,我有这个测试: describe("onAfterSwipe", () => { it("Should call a handler after swiping", async () => { const onAfterSwipe = jest.fn(); const wrapper = mount( <Swipeable onAfterSwipe={onAfterSwipe}>Hello</Swipeable> );

我有这个测试:

describe("onAfterSwipe", () => {
  it("Should call a handler after swiping", async () => {
    const onAfterSwipe = jest.fn();
    const wrapper = mount(
      <Swipeable onAfterSwipe={onAfterSwipe}>Hello</Swipeable>
    );

    swipe(wrapper, 500);

    await wait(600);

    expect(onAfterSwipe).toHaveBeenCalledTimes(1);
  });
});
description(“onAfterSwipe”,()=>{
它(“刷卡后应该调用处理程序”,async()=>{
const-onAfterSwipe=jest.fn();
常量包装器=装入(
你好
);
刷卡(包装纸,500);
等待等待(600);
预期(在刷卡后)。已被催缴时间(1);
});
});
我正在等待600ms以检查是否调用了该函数(动画结束后调用onAfterSwipe),我想执行以下操作:

describe("onAfterSwipe", () => {
  it("Should call a handler after swiping", (done) => {
    const onAfterSwipe = jest.fn();
    const wrapper = mount(
      <Swipeable onAfterSwipe={onAfterSwipe}>Hello</Swipeable>
    );

    swipe(wrapper, 500);

    onAfterSwipe.called((args) => {
      expect(onAfterSwipe).toHaveBeenCalledWith("right");
      done();
    })
  });
});
description(“onAfterSwipe”,()=>{
它(“刷卡后应调用处理程序”,(完成)=>{
const-onAfterSwipe=jest.fn();
常量包装器=装入(
你好
);
刷卡(包装纸,500);
onAfterSwipe.called((args)=>{
期望(在刷卡后)与(“右”);
完成();
})
});
});

我对笑话不太熟悉,但我认为你可以做到:

const onAfterSwipe = jest.fn(args => {
   // expect args to be "right"
   done();
});