私は現在サイロンを学んでいます。マイコード:モカの約束遅れ
const bluebird = require('bluebird');
const sinon = require('sinon');
const sinonTest = require('sinon-test')(sinon);
sinon.test = sinonTest;
describe('xxx', function _test() {
this.timeout(2000);
it('should', sinon.test(function() {
return new bluebird.Promise((resolve, reject) => {
try {
console.log('123');
resolve();
} catch (err) {
reject(err);
};
})
.then(() => console.log('456'))
.delay(100)
.then(() => console.log('789'))
.then(function() {
})
}));
});
出力:
xxx
123
456
なぜ上記のコードはタイムアウトしdelay
で立ち往生?おかげ
UPDATE
const bluebird = require('bluebird');
const sinon = require('sinon');
const sinonTest = require('sinon-test')(sinon);
sinon.test = sinonTest;
describe('xxx', function _test() {
this.timeout(2000);
it('should', sinon.test(function() {
return bluebird
.delay(100)
.then(() => console.log('789'));
}));
});
出力:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves
UPDATE
おかげ@Louis。 useFakeTimers
の設定は問題ありません。
しかし、私はちょうど混乱しています。なぜ私のプロジェクトでは、既存のテストに問題はありません。useFakeTimers
がデフォルトでtrueに設定されていますか? useFakeTimers
がtrueに設定されている場合、sinonTest()
では約束遅延を使用できませんか?
ちなみにsinon
を1.17.6
から2.4.1
にアップグレードすると、この問題が発生しました。 ありがとう
'{useFakeTimers:false}'が設定されている場合、 'delay'は動作しませんか? – BAE
私はあなたの質問でコードを取り、新しいファイルに置き換え、2番目のパラメータ '{useFakeTimers:false}'を追加して編集し、必要なパッケージをインストールしてMochaを実行して動作させます。私はすべての 'console.log'出力を得て、タイムアウトはありません。それは私の答えを書く前にそれをやったときに機能し、今は動作します。あなたは間違ったことをしているに違いない。 – Louis
はい。それは今働いている。あなたは私のいくつかの質問を解決しました。ありがとう。しかし、私はちょうど混乱しています。なぜ私のプロジェクトでは 'useFakeTimers'が設定されていない既存のテストに問題はありませんか? – BAE