私はちょうど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)
あなたのコンソールログplsを投稿する –