chore(util-registry.spec): added a test for destroyAll Method

This commit is contained in:
Johannes Eder 2021-06-21 16:03:36 +02:00 committed by Sarah Vaupel
parent 01c239d6c3
commit ded4c1f64e
2 changed files with 42 additions and 1 deletions

View File

@ -103,8 +103,10 @@ export class UtilRegistry {
utilsInScope.forEach((util) => {
//if(DEBUG_MODE > 2) {
console.log('Destroying Util: ', {util});
//}
//}#
let utilIndex = this._activeUtilInstancesWrapped.indexOf(util);
util.destroy();
this._activeUtilInstancesWrapped.splice(utilIndex, 1);
});
}

View File

@ -199,6 +199,44 @@ describe('UtilRegistry', () => {
});
});
});
describe('destroyAll()', () => {
let testScope;
let testElement;
let firstUtil;
beforeEach( () => {
testScope = document.createElement('div');
testElement = document.createElement('div');
testElement.classList.add('util3');
testScope.appendChild(testElement);
utilRegistry.register(TestUtil3);
utilRegistry.initAll(testScope);
firstUtil = utilRegistry._activeUtilInstancesWrapped[0];
spyOn(firstUtil.instance, 'destroy');
});
it('Util should be destroyed', () => {
utilRegistry.destroyAll(testScope);
expect(utilRegistry._activeUtilInstancesWrapped.length).toBe(0);
expect(firstUtil.instance.destroy).toHaveBeenCalled();
});
it('Util out of scope should not be destroyed', () => {
let outOfScope = document.createElement('div');
expect(utilRegistry._activeUtilInstancesWrapped.length).toEqual(1);
utilRegistry.destroyAll(outOfScope);
expect(utilRegistry._activeUtilInstancesWrapped.length).toEqual(1);
expect(utilRegistry._activeUtilInstancesWrapped[0]).toBe(firstUtil);
expect(firstUtil.instance.destroy).not.toHaveBeenCalled();
});
});
});
// test utilities
@ -219,6 +257,7 @@ class TestUtil2 { }
class TestUtil3 {
constructor() {}
start() {}
destroy() {}
}
@Utility({ selector: '#throws' })