Jasmine nor Angular will ever remove it automatically, maybe to help you to get more details about your test execution.
To remove it you simply use afterEach(...)
, like:
beforeEach(() => {
fixture = TestBed.createComponent(MyComponent);
comp = fixture.componentInstance;
debugElement = fixture.debugElement;
element = debugElement.nativeElement;
});
afterEach(() => {
document.body.removeChild(element);
});
For none Angular users:
afterEach(() => {
document.body.innerHTML = '';
});
Above clears all default
<script>
tags, but that does not matter
(because they did already run, and Karma does never refresh the browser, at least not till all tests finish).