小编VP_*_*dra的帖子

类型错误:无法读取未定义的属性“地址”

我需要一些测试节点 js 代码的帮助。我正在使用 mocha 和 supertest,但我不断收到与测试标题相同的错误。我还使用 mongoose 连接到 mongo 服务器,在我运行测试之前,我添加了一些来宾对象。我已经被难住了 2 天,所以任何帮助表示赞赏。

这是测试错误

  0 passing (96ms)
  1 failing

  1) Guestss
       GET /guests
         should GET all the guests:
     TypeError: Cannot read property 'address' of undefined
      at Test.serverAddress (node_modules/supertest/lib/test.js:55:18)
      at new Test (node_modules/supertest/lib/test.js:36:12)
      at Object.get (node_modules/supertest/index.js:25:14)
      at Context.<anonymous> (test/functional/api/guestTest.js:95:18)
Run Code Online (Sandbox Code Playgroud)

这是测试代码

describe("GET /guests", () => {
        it("should GET all the guests", done => {
            console.log("before");
            request(server)
                .get("/guests")
                .set("Accept", "application/json")
                .expect("Content-Type", /json/)
                .expect(200)
                .end((err, res) => {
                    try {
                        expect(res.body).to.be.a("array");
                        expect(res.body.length).to.equal(2);
                        let result = …
Run Code Online (Sandbox Code Playgroud)

mocha.js mongoose node.js supertest

3
推荐指数
1
解决办法
2278
查看次数

标签 统计

mocha.js ×1

mongoose ×1

node.js ×1

supertest ×1