未找到 TypeScript before() 和 after()

问题描述

尝试使用 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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...