Browse Source

feat: add removeContent method

pull/3586/head
Arman Ozak 6 years ago
parent
commit
3348bf716e
  1. 7
      npm/ng-packs/packages/core/src/lib/services/dom-insertion.service.ts
  2. 14
      npm/ng-packs/packages/core/src/lib/tests/dom-insertion.service.spec.ts

7
npm/ng-packs/packages/core/src/lib/services/dom-insertion.service.ts

@ -18,4 +18,11 @@ export class DomInsertionService {
return element;
}
removeContent(element: HTMLScriptElement | HTMLStyleElement) {
const hash = generateHash(element.textContent);
this.inserted.delete(hash);
element.parentNode.removeChild(element);
}
}

14
npm/ng-packs/packages/core/src/lib/tests/dom-insertion.service.spec.ts

@ -49,4 +49,18 @@ describe('DomInsertionService', () => {
expect(element.tagName).toBe('STYLE');
});
});
describe('#removeContent', () => {
it('should remove inserted element and the hash for the content', () => {
expect(document.head.querySelector('style')).toBeNull();
const element = spectator.service.insertContent(
CONTENT_STRATEGY.AppendStyleToHead('.test {}'),
);
expect(spectator.service.inserted.has(1437348290)).toBe(true);
spectator.service.removeContent(element);
expect(spectator.service.inserted.has(1437348290)).toBe(false);
expect(document.head.querySelector('style')).toBeNull();
});
});
});

Loading…
Cancel
Save