u2w-merge #192

Merged
savau merged 344 commits from u2w-merge into master 2022-09-02 18:00:29 +02:00
2 changed files with 42 additions and 1 deletions
Showing only changes of commit ded4c1f64e - Show all commits

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' })