0
プロシージャ内の特定のステップが実行されていることを確認するためにsinonを使用しようとしています。テストしているメソッドが指定された関数を呼び出すことを確認します。ここでsinonを使用して、メソッドが最終的に呼び出されるかどうかをテストする方法
は、私は現在、何をすべきかです:
describe('Native calls handling', function() {
var ctrl;
beforeEach(function() {
ctrl = new EthernetController($placeholder, notifications, null, nav);
});
// What I currently do
it('Should perform internet check on `Connected` event', function(done) {
var errorTimeout = setTimeout(function() {
internetCheck.restore();
done(new Error('Assertion failed, internetCheck was not executed'));
}, 1500);
var internetCheck = sinon.stub(ctrl, 'internetCheck', function() {
clearTimeout(errorTimeout);
internetCheck.restore();
done();
return Promise.resolve(true);
});
app.notify('system:ethernet:connected');
});
// Functionality I'm looking for
it('Should perform internet check on `Connected` event', function(done) {
var internetCheck = sinon.stub(ctrl, 'internetCheck', function() {
return Promise.resolve(true);
});
// Fail the test if the function is not called within $ ms
// Also restore the stub
internetCheck.cancelationTime = 1500;
// Trigger the assertion after/if the function is called
internetCheck.whenCalled(function(params...) {// assertion })
.timedOut(done);
app.notify('system:ethernet:connected');
});
});
Connected
イベントが最後にinternetCheck
私は
探しているものに似た何かがあるのを行います非同期手順をトリガします編集: 私の本当の問題は、使用されたメソッドが内部的に約束していたが、voidを返すので、手続きが完了したときにわかりやすい方法がない。 私はのNode.jsですthis solutionにつまずいてきた