Ensure that the DOM event listeners are removed at the end of the relevant EventBus unit-tests, to prevent the tests from interfering with each other

This commit is contained in:
Jonas Jenwald 2018-09-20 23:08:38 +02:00
parent 250e55b0d9
commit f317a2cb40

View File

@ -272,13 +272,17 @@ describe('ui_utils', function() {
eventBus.on('test', function() { eventBus.on('test', function() {
count++; count++;
}); });
document.addEventListener('test', function() { function domEventListener() {
count++; done.fail('shall not dispatch DOM event.');
}); }
document.addEventListener('test', domEventListener);
eventBus.dispatch('test'); eventBus.dispatch('test');
Promise.resolve().then(() => { Promise.resolve().then(() => {
expect(count).toEqual(1); expect(count).toEqual(1);
document.removeEventListener('test', domEventListener);
done(); done();
}); });
}); });
@ -291,13 +295,17 @@ describe('ui_utils', function() {
eventBus.on('test', function() { eventBus.on('test', function() {
count++; count++;
}); });
document.addEventListener('test', function() { function domEventListener() {
count++; count++;
}); }
document.addEventListener('test', domEventListener);
eventBus.dispatch('test'); eventBus.dispatch('test');
Promise.resolve().then(() => { Promise.resolve().then(() => {
expect(count).toEqual(2); expect(count).toEqual(2);
document.removeEventListener('test', domEventListener);
done(); done();
}); });
}); });