首页 > 解决方案 > 使用 chai-http 测试的测试没有运行

问题描述

我尝试使用 chai-http 测试我的路由文件,但它归档是因为:“TypeError:套件参数“title”必须是一个字符串。收到类型“number”

我的 test.js

const { assert, should, expect, sinon } = require("../baseTest");
const chai = require("chai");
chai.use(require("chai-http"));

describe.only("Test the "/" routes", () => {
  const server = "http://localhost:3000";
  it("", done => {
    chai
      .request(server)
      .get("/")
      .end((err, res) => {
        if(err) done(err);
        res.should.have.status(200);
        done();
      });
  });
});

路线:

module.exports = (express, DefaultController) => {
    const api = express.Router();

    api.get('/', DefaultController.help);
    api.get('/status', DefaultController.status);
    return api;
};

标签: javascriptmocha.jschaichai-http

解决方案


最后我解决了。问题出在 describe 函数的套件参数中

前:

describe.only("Test the "/" routes", () => {});

describe.only("Test the / routes", () => {});

推荐阅读