Skip to content

Commit

Permalink
Test coverage for removeEventListener
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffposnick committed Mar 15, 2019
1 parent 41666a8 commit 122c0d5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/workbox-window/unit/test-Workbox.mjs
Expand Up @@ -868,5 +868,30 @@ describe(`[workbox-window] Workbox`, function() {
expect(externalActivated2Spy.callCount).to.equal(0);
});
});

describe(`removeEventListener()`, function() {
it(`will register and then unregister event listeners of a given type`, function() {
const eventType = 'testEventType';
const event = {type: eventType};
const eventListener1 = sandbox.stub();
const eventListener2 = sandbox.stub();

const wb = new Workbox(uniq('sw-clients-claim.tmp.js'));
wb.addEventListener(eventType, eventListener1);
wb.addEventListener(eventType, eventListener2);

wb.dispatchEvent(event);
expect(eventListener1.calledOnceWith(event)).to.be.true;
expect(eventListener2.calledOnceWith(event)).to.be.true;

wb.removeEventListener(eventType, eventListener2);
wb.dispatchEvent(event);

// The remaining stub should be called again.
expect(eventListener1.calledTwice).to.be.true;
// Make sure the removed stub was called only once.
expect(eventListener2.calledOnce).to.be.true;
});
});
});
});

0 comments on commit 122c0d5

Please sign in to comment.