我剛剛開始使用TDD,而且我遇到了一個奇怪的問題。我爲一個(也是簡單的)user
模塊寫了一個非常簡單的測試。由於某種原因,測試表示hasOwnProperty
函數不存在。沒有找到柴的功能
測試代碼:
var expect = require('chai').expect;
var user = require('./user');
describe('Name', function() {
it('Should have a name', function() {
expect(user).to.have.ownProperty('name');
});
it('The name property should be a string', function() {
expect(user.name).to.be.a('string');
});
it('Should have non empty string as name', function() {
expect(user.name).to.have.length.above(0);
});
});
模塊:
var user = Object.create(null);
user.name = 'Name';
// exports
module.exports = user;
運行$ mocha test.js
之後,第一測試失敗。 Chai ownProperty reference
有什麼建議嗎?謝謝!
控制檯輸出:
Name
1) Should have a name
✓ The name property should be a string
✓ Should have non empty string as name
2 passing (12ms)
1 failing
1) Name Should have a name:
TypeError: obj.hasOwnProperty is not a function
at Assertion.assertOwnProperty (node_modules/chai/lib/chai/core/assertions.js:937:13)
at Assertion.ctx.(anonymous function) [as ownProperty] (node_modules/chai/lib/chai/utils/addMethod.js:41:25)
at Context.<anonymous> (test.js:6:26)
張貼您的控制檯日誌請致電 –