node tests: Simplify trigger stubbing in stream_events.js.

This test verifies the following line of code:

    $(document).trigger($.Event('subscription_remove_done.zulip', {sub: sub}));

Before this change, the mocking mechanism used `$(document).on(...)`
to set the function that gets called on trigger, but it didn't clear
any of the other handlers.

Since all we care about is making sure that the event gets triggered,
we now just override `$(document).trigger`.
This commit is contained in:
Steve Howell 2017-07-06 09:43:41 -04:00
parent 38e3d2fc11
commit 74f9612147
1 changed files with 14 additions and 11 deletions

View File

@ -287,18 +287,21 @@ stream_data.add_sub('Frontend', frontend);
override('narrow_state.is_for_stream_id', function () {
return true;
});
global.with_stub(function (stub) {
$(document).on('subscription_remove_done.zulip', stub.f);
var updated = false;
override('current_msg_list.update_trailing_bookend', function () {
updated = true;
});
stream_events.mark_unsubscribed(frontend);
var args = stub.get_args('event');
assert.equal(updated, true);
assert.deepEqual(args.event.sub, frontend);
var updated = false;
override('current_msg_list.update_trailing_bookend', function () {
updated = true;
});
var event_triggered = false;
$(document).trigger = function (ev) {
assert.equal(ev.name, 'subscription_remove_done.zulip');
assert.deepEqual(ev.data.sub, frontend);
event_triggered = true;
};
stream_events.mark_unsubscribed(frontend);
assert.equal(updated, true);
assert.equal(event_triggered, true);
});
}());