【问题标题】:Function done() not recognized by jest with typescript带有打字稿的玩笑无法识别功能完成()
【发布时间】:2020-07-28 10:10:43
【问题描述】:

我正在尝试在测试中使用 done() 函数,如下所示:

it('button click -> call selectProduct', async () => {
  // wrapper is defined properly in a beforeEach() with shallowMount()
  const spy = jest.spyOn(wrapper.vm, 'selectProduct');
  wrapper.find('button').trigger('click');
  setTimeout(() => {
      expect(spy).toBeCalledTimes(1);
      done();
  });
});

但是 vscode 告诉我Cannot find name 'done'。但是,done 在文档中使用时没有 import 语句。我做错了什么?

【问题讨论】:

    标签: typescript vue.js testing jestjs


    【解决方案1】:

    你错过了在你的测试回调中接受它作为参数

    it('button click -> call selectProduct', async ( done ) => {
                                                    ^ here
    

    【讨论】:

      猜你喜欢
      • 2020-01-18
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 2019-03-22
      • 1970-01-01
      • 1970-01-01
      • 2020-02-01
      • 2018-12-09
      相关资源
      最近更新 更多