私はこのモジュール(2)のテスト(1)を実装しようとしています。
私の目的は、特定のイベントが発生したときにコレクションが取得されるかどうかをチェックすることです。
(2)の私のコメントから分かるように、私はメッセージを受け取りますError: Expected a spy, but got Function.
モジュールは動作しますが、テストは失敗します。何か案は?スパイが必要ですが、機能があります。
(1)
// jasmine test module
describe('When onGivePoints is fired', function() {
beforeEach(function() {
spyOn(this.view.collection, 'restartPolling').andCallThrough();
app.vent.trigger('onGivePoints');
});
it('the board collection should be fetched', function() {
expect(this.view.collection.restartPolling).toHaveBeenCalled();
// Error: Expected a spy, but got Function.
});
});
(2)
// model view module
return Marionette.CompositeView.extend({
initialize: function() {
this.collection = new UserBoardCollection();
this.collection.startPolling();
app.vent.on('onGivePoints', this.collection.restartPolling);
},
// other code
});
何が起こっているかを見るのに十分なコードがありません。関数が属するオブジェクト定義と、少なくともオブジェクトをインスタンス化するコードを含めて、個々の関数以上のものを含めてください。 –
@DerickBaileyお時間をいただきありがとうございます。モードコードで質問を更新しました。 –
私はJasmineではなくQUnitを使用していますが、app.vent.triggerをbeforeEachではなくitメソッドに呼び出すべきですか? – codemonkey