问题描述
尝试使用 Jest/SuperTest 在 TypeScript 中运行测试 - 但是当我运行 npm test
时,它返回以下错误:
我缺少/未导入什么包?
FAIL test/test.ts
● Test suite Failed to run
test/test.ts:8:3 - error TS2304: Cannot find name 'before'.
8 before(PlatformTest.bootstrap(Server));
~~~~~~
test/test.ts:9:3 - error TS2304: Cannot find name 'before'.
9 before(() => {
~~~~~~
test/test.ts:12:3 - error TS2304: Cannot find name 'after'.
12 after(PlatformTest.reset);
这些是我的导入:
import {PlatformTest} from "@tsed/common";
import * as SuperTest from "supertest";
import {Server} from "../src/Server";
解决方法
请检查您是否选择了正确的全局变量,开玩笑地说,没有 after()
或 before()
,但是例如afterEach()
或 beforeEach()
。
可以在此处找到所有开玩笑的全局变量:https://jestjs.io/docs/api