Angular 4 fixture component persists in DOM during Jasmine tests

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).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)