From 35aba2b9aa892b20194cdcd86f5063c7c0892702 Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Tue, 27 Feb 2018 17:02:47 +1000 Subject: [PATCH 1/2] test(fromEvent): add failing expectation --- spec/observables/fromEvent-spec.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/observables/fromEvent-spec.ts b/spec/observables/fromEvent-spec.ts index 893f66f6cd..f2d57d0010 100644 --- a/spec/observables/fromEvent-spec.ts +++ b/spec/observables/fromEvent-spec.ts @@ -132,16 +132,17 @@ describe('fromEvent', () => { }); }); - it('should pass through options to addEventListener', () => { - let actualOptions; + it('should pass through options to addEventListener and removeEventListener', () => { + let onOptions; + let offOptions; const expectedOptions = { capture: true, passive: true }; const obj = { addEventListener: (a: string, b: EventListenerOrEventListenerObject, c?: any) => { - actualOptions = c; + onOptions = c; }, removeEventListener: (a: string, b: EventListenerOrEventListenerObject, c?: any) => { - //noop + offOptions = c; } }; @@ -152,7 +153,8 @@ describe('fromEvent', () => { subscription.unsubscribe(); - expect(actualOptions).to.equal(expectedOptions); + expect(onOptions).to.equal(expectedOptions); + expect(offOptions).to.equal(expectedOptions); }); it('should pass through events that occur', (done: MochaDone) => { From f1872b0ae217e7e27ef3b051f248abf67d802285 Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Tue, 27 Feb 2018 17:13:19 +1000 Subject: [PATCH 2/2] fix(fromEvent): pass options in unsubscribe Closes #3349 --- src/internal/observable/fromEvent.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/observable/fromEvent.ts b/src/internal/observable/fromEvent.ts index 4a69a287ba..6b3d7e8003 100644 --- a/src/internal/observable/fromEvent.ts +++ b/src/internal/observable/fromEvent.ts @@ -166,7 +166,7 @@ function setupSubscription(sourceObj: EventTargetLike, eventName: string, } else if (isEventTarget(sourceObj)) { const source = sourceObj; sourceObj.addEventListener(eventName, handler as EventListener, options); - unsubscribe = () => source.removeEventListener(eventName, handler as EventListener); + unsubscribe = () => source.removeEventListener(eventName, handler as EventListener, options); } else if (isJQueryStyleEventEmitter(sourceObj)) { const source = sourceObj; sourceObj.on(eventName, handler);