带有打字稿的玩笑无法识别功能完成()

Posted

技术标签:

【中文标题】带有打字稿的玩笑无法识别功能完成()【英文标题】: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 语句。我做错了什么?

【问题讨论】:

【参考方案1】:

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

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

【讨论】:

以上是关于带有打字稿的玩笑无法识别功能完成()的主要内容,如果未能解决你的问题,请参考以下文章