【发布时间】:2017-10-19 03:04:03
【问题描述】:
我有以下JSON 有效载荷:
"app": {
"name": "myapp",
"version": "1.0.0",
"last_commit": {
"author_name": "Jon Snow"
"author_email": "my@email.com"
}
}
以及以下.js 文件(使用Mocha、Supertest 和Should):
var supertest = require('supertest')
var should = require('should')
var server = supertest.agent('http://localhost:3001')
describe('GET /', function () {
it('should respond with JSON', function (done) {
server
.get('/')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
.end(function (err, res) {
var payload = res.body.app;
payload.should.have.property("app");
payload.should.have.property("name");
payload.should.have.property("version");
payload.should.have.property("last_commit");
payload.should.have.property("last_commit.author_name");
payload.should.have.property("last_commit.author_email");
done();
});
});
});
当我测试应用程序时,我收到以下错误消息:
Uncaught AssertionError: expected Object {
"name": "myapp",
"version": "1.0.0",
"last_commit": Object {
"author_name": "Jon Snow"
"author_email": "my@email.com"
}
} to have property 'last_commit.author_name'
为什么我会在这些行中收到断言错误?
payload.should.have.property("last_commit.author_name");
payload.should.have.property("last_commit.author_email");
【问题讨论】:
标签: json node.js mocha.js supertest should.js