chore(util_registry_test): added test case to deregister method when instances should be destroyed
This commit is contained in:
parent
f1ef2e5ec7
commit
01c239d6c3
@ -178,15 +178,12 @@ export class UtilRegistry {
|
||||
util: util,
|
||||
index: index,
|
||||
}))
|
||||
.filter((activeUtil) => activeUtil.util.name === name)
|
||||
.filter((activeUtil) => activeUtil.util.util.name === name)
|
||||
.forEach((activeUtil) => {
|
||||
// destroy util instance
|
||||
activeUtil.util.destroy();
|
||||
delete this._activeUtilInstancesWrapped[activeUtil.index];
|
||||
activeUtil.util.instance.destroy();
|
||||
this._activeUtilInstancesWrapped = this._activeUtilInstancesWrapped.splice(activeUtil.index, 1);
|
||||
});
|
||||
|
||||
// get rid of now empty array slots
|
||||
this._activeUtilInstancesWrapped = this._activeUtilInstancesWrapped.filter((util) => !!util);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -24,24 +24,6 @@ describe('UtilRegistry', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('deregister()', () => {
|
||||
it('should remove util', () => {
|
||||
// register util
|
||||
utilRegistry.register(TestUtil1);
|
||||
let foundUtil = utilRegistry.find(TestUtil1.name);
|
||||
expect(foundUtil).toBeTruthy();
|
||||
|
||||
// deregister util
|
||||
utilRegistry.deregister(TestUtil1.name);
|
||||
foundUtil = utilRegistry.find(TestUtil1.name);
|
||||
expect(foundUtil).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should destroy util instances if requested', () => {
|
||||
pending('TBD');
|
||||
});
|
||||
});
|
||||
|
||||
describe('setup()', () => {
|
||||
|
||||
it('should catch errors thrown by the utility', () => {
|
||||
@ -107,6 +89,51 @@ describe('UtilRegistry', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('deregister()', () => {
|
||||
let testScope;
|
||||
let testElement1;
|
||||
let testElement2;
|
||||
|
||||
beforeEach(() => {
|
||||
testScope = document.createElement('div');
|
||||
testElement1 = document.createElement('div');
|
||||
testElement2 = document.createElement('div');
|
||||
testElement1.classList.add('util1');
|
||||
testElement2.classList.add('util1');
|
||||
testScope.appendChild(testElement1);
|
||||
testScope.appendChild(testElement2);
|
||||
});
|
||||
|
||||
it('should remove util', () => {
|
||||
// register util
|
||||
utilRegistry.register(TestUtil1);
|
||||
let foundUtil = utilRegistry.find(TestUtil1.name);
|
||||
expect(foundUtil).toBeTruthy();
|
||||
|
||||
// deregister util
|
||||
utilRegistry.deregister(TestUtil1.name);
|
||||
foundUtil = utilRegistry.find(TestUtil1.name);
|
||||
expect(foundUtil).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should destroy util instances if requested', () => {
|
||||
utilRegistry.register(TestUtil1);
|
||||
let foundUtil = utilRegistry.find(TestUtil1.name);
|
||||
expect(foundUtil).toBeTruthy();
|
||||
|
||||
utilRegistry.setup(TestUtil1, testScope);
|
||||
let firstActiveUtil = utilRegistry._activeUtilInstancesWrapped[0];
|
||||
expect(utilRegistry._activeUtilInstancesWrapped.length).toEqual(2);
|
||||
expect(utilRegistry._activeUtilInstancesWrapped[0].element).toEqual(testElement1);
|
||||
|
||||
spyOn(firstActiveUtil.instance, 'destroy');
|
||||
|
||||
utilRegistry.deregister(TestUtil1.name, true);
|
||||
expect(utilRegistry._activeUtilInstancesWrapped[0]).toBeFalsy();
|
||||
expect(firstActiveUtil.instance.destroy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('initAll()', () => {
|
||||
it('should setup all the utilities', () => {
|
||||
spyOn(utilRegistry, 'setup');
|
||||
@ -181,6 +208,8 @@ class TestUtil1 {
|
||||
this.element = element;
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
destroy() {}
|
||||
}
|
||||
|
||||
@Utility({ selector: '#util2' })
|
||||
|
||||
Reference in New Issue
Block a user