【问题标题】:AssertionError: expected undefined to equal 200AssertionError:预期未定义等于 200
【发布时间】:2021-11-23 08:32:29
【问题描述】:
const express = require("express");
const app = express();
const router = express.Router();

router.get('/postp',(req,res)=>{
  res.status(200);
})

app.listen(PORT, () => {
  console.log(`Connected to PORT : ${PORT}`);
});
module.exports = app;

测试用例:

const chai = require('chai');
const request = require('supertest');
const app = require('../app');
const post = require('../router/post');
const expect = chai.expect;

describe('Blog',function(){

  it('get blogs', function(done){
    const response =  request(app).get('/postp');
    expect(response.status).to.be.equal(200);
    done();
  })
})

有什么问题? 请说明,是因为我无法访问应用程序还是其他原因。

为什么它没有运行

【问题讨论】:

    标签: node.js express mocha.js chai mern


    【解决方案1】:

    尝试使用来自chai的请求。

    const chai = require('chai');
    const request = require('supertest');
    const app = require('../app');
    const post = require('../router/post');
    const expect = chai.expect;
    
    describe('Blog',function(){
    
      it('get blogs', function(done){
        const response =  chai.request(app).get('/postp')
                          .end((err, res) => {
                            res.should.have.status(200);
                           })
        done();
      })
    })
    

    我建议您查看this 链接,它提供了有关断言库和 chai 的更多详细信息。

    【讨论】:

      猜你喜欢
      • 2019-08-27
      • 1970-01-01
      • 2015-12-19
      • 2020-09-21
      • 2017-04-19
      • 1970-01-01
      • 2016-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多