From 74f961214795be603c7107162459c8229d7bf6d1 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 6 Jul 2017 09:43:41 -0400 Subject: [PATCH] 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`. --- frontend_tests/node_tests/stream_events.js | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/frontend_tests/node_tests/stream_events.js b/frontend_tests/node_tests/stream_events.js index ea206cbc59..85e24a6aa1 100644 --- a/frontend_tests/node_tests/stream_events.js +++ b/frontend_tests/node_tests/stream_events.js @@ -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); }); }());