Typescript函数返回笑话测试-返回的类型应该是

时间:2019-10-09 18:18:44

标签: typescript jestjs

如果我使用TypeScript将一个笑话测试封装在一个函数中,那么预期的返回类型应该是什么?谢谢。

const foo:JestReturnType = () => test('this is a test', expect(true).toBeTruthy());

1 个答案:

答案 0 :(得分:1)

testit的返回值为void

const foo = (): void =>
  test('this is a test', () => {
    expect(true).toBeTruthy();
  });

describe('test suites', () => {
  foo();
});

单元测试结果:

 PASS  src/stackoverflow/58310060/index.spec.ts (10.251s)
  test suites
    ✓ this is a test (6ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        12.401s

源代码:https://github.com/mrdulin/jest-codelab/tree/master/src/stackoverflow/58310060