我得到如下結果由摩卡失敗消息:無法獲取對象等於
Uncaught AssertionError: expected Object { name: 'John Doe' } to be Object { name: 'John Doe' }
+ expected - actual
這裏是我的測試代碼:
describe("A user gets registered", function() {
it('should create a SINGLE user on /api/register POST', function (done) {
//calling REGISTER api
server
.post('/api/register')
.send({
name: "John Doe",
username: "john",
password: "open"
})
.expect("Content-type", /json/)
.expect(200)
.end(function (err, res) {
var data = {
"name": "John Doe"
};
res.status.should.equal(200);
res.body.should.equal(data);
done();
});
});
});
這是我的實際代碼:
router.post('/', function (req, res) {
var data = {name: 'John Doe'};
res.status(200).json(data);
});
module.exports = router;
但是,我不應該從摩卡得到一個失敗的消息,因爲兩個對象都是一樣的。但不知何故,他們並非如此,我真的不知道我做錯了什麼。
我已經檢查了兩個對象的間距,所以不應該如此。
嘗試'deepEqual'? http://stackoverflow.com/questions/13225274/the-difference-between-assert-equal-and-assert-deepequal-in-javascript-testing-w在JavaScript'({} === {})'返回 – evolutionxbox
''''' 'false'意味着沒有2個對象可以直接比較,但是它們的關鍵值對可以進行比較。 –