私のコードを実行しないで期待しますか?ありがとう理由のsetTimeoutにおける記述のうち、
更新 次のコードを試してみましたが、Error: timeout of 2000ms exceeded
を取得しました。これは、done
が呼び出されていないためです。 this.myOBJ.toBeTestedFunction({});
の実行が完了してから、期待通りに実行する必要があります。コードを修正するには?
it('should', sinon.test(function(done) {
const stubFindOne = this.stub(this.myOBJ, 'findOne');
stubFindOne.returns(bluebird.reject(new Error('Should have failed')));
this.myOBJ.toBeTestedFunction({});
setTimeout(function _expect() {
console.log('++++++++++++ 1 ++++++++++++++++++++++++++++++++++++++++');
console.log('this.spyLog', this.spyLog.args);
expect(this.spyLog.args[0][0].toString()).to.be.equal('Error: Should have failed');
console.log('++++++++++++ 2 ++++++++++++++++++++++++++++++++++++++++');
done();
}, 100);
}));
UPDATE
私の次のコードは動作します。それを改善する方法は?書かれたよう
it('should', sinon.test(function() {
const stubFindOne = this.stub(this.myOBJ, 'findOne');
stubFindOne.returns(bluebird.reject(new Error('Should have failed')));
return new bluebird.Promise((resolve, reject) => {
this.myOBJ.tobetestedFunction();
resolve();
})
.delay(1000)
.then(() => {
expect(this.spyLog.args[2][0].toString()).to.be.equal('Error: Should have failed');
});
}));
の評価に向かって、あなたのテストを進めるために嘲笑応答を使用するのと同じように「正しい方法」は、著しくより困難であるこの種の試験を行う
は試してみましたが、 'エラーを得た:タイムアウト「これは良い計画ではない」ということについてもっと詳しく教えてもらえますか?2000年には – BAE
を超えましたか? – BAE
はい。同意する。しかし、これは私が現在変更してはいけない既存のコードのテストを書く仕事です。非同期関数の適切な単体テストを書くには? – BAE