相关疑难解决方法(0)

在mocha中运行supertest时如何获得实际的服务器错误?

我有使用supertest和mocha的代码:

import request from 'supertest';

//....

var newGame;
describe('Creating game', function() {
  beforeEach(function(done) {
    request(app)
      .post('/api/games')
      .send({
        owner: 'Mr. X',
      })
      .expect(201)
      .expect('Content-Type', /json/)
      .end((err, res) => {
        if (err) {
          return done(err);
        }
        newGame = res.body;
        done();
      });
  });    

  describe('the created game', function() {

    it('should name the specified owner', function() {
      newGame.owner.should.equal('Mr. X');
    });

   ...
  })
});
Run Code Online (Sandbox Code Playgroud)

当服务器代码抛出一些异常(例如访问未定义对象的属性)时,我得到了这个堆栈跟踪

Error: expected 201 "Created", got 500 "Internal Server Error"
  at Test._assertStatus (D:\Codes\theApp\node_modules\supertest\lib\test.js:232:12)
  at Test._assertFunction (D:\Codes\theApp\node_modules\supertest\lib\test.js:247:11)
  at Test.assert (D:\Codes\theApp\node_modules\supertest\lib\test.js:148:18)
  at Server.assert (D:\Codes\theApp\node_modules\supertest\lib\test.js:127:12) …
Run Code Online (Sandbox Code Playgroud)

mocha.js node.js supertest

12
推荐指数
1
解决办法
3543
查看次数

标签 统计

mocha.js ×1

node.js ×1

supertest ×1