Skip to content

Commit

Permalink
fix(fromEvent): pass options in unsubscribe (#3413)
Browse files Browse the repository at this point in the history
* test(fromEvent): add failing expectation

* fix(fromEvent): pass options in unsubscribe
  • Loading branch information
cartant authored and benlesh committed Mar 8, 2018
1 parent e2cd3a2 commit d287218
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions spec/observables/fromEvent-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,17 @@ describe('Observable.fromEvent', () => {
expect(subscribe).to.throw(TypeError, 'Invalid event target');
});

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;
}
};

Expand All @@ -149,7 +150,8 @@ describe('Observable.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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/observable/FromEventObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class FromEventObservable<T> extends Observable<T> {
} else if (isEventTarget(sourceObj)) {
const source = sourceObj;
sourceObj.addEventListener(eventName, <EventListener>handler, <boolean>options);
unsubscribe = () => source.removeEventListener(eventName, <EventListener>handler);
unsubscribe = () => source.removeEventListener(eventName, <EventListener>handler, <boolean>options);
} else if (isJQueryStyleEventEmitter(sourceObj)) {
const source = sourceObj;
sourceObj.on(eventName, handler);
Expand Down

0 comments on commit d287218

Please sign in to comment.