在等待/异步返回时进行Jest单元测试发现的行

时间:2020-09-11 00:31:51

标签: javascript node.js unit-testing jestjs

我是Jest单元测试的新手,我一直在使用Mocha ...

我的问题与下面的基本代码和单元测试有关,我有一个uncovered line,看不到为什么?

任何帮助/指导都将不胜感激,我确信我缺少一些愚蠢的东西。

index.js(如下)

function sleep(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

module.exports = {
  async testfunction() {
    await sleep(500);
    return 'Hello World !'
  }
}

index.test.js(如下)

const myfunctions = require('.');

test('testing testfunction from myfunctions', async () => {
  expect(await myfunctions.testfunction()).toBe('Hello World !')
});

使用cli命令jest --coverage

Results image from cli

0 个答案:

没有答案