jeudi 3 octobre 2019

Angular Testing: Exception causes different test to fail

The following code gives me some wired output. The exception triggered in Test 1 causes Test 2 to fail. Its okay that Test 1 does not fail because the exceptions comes up asynchronous. But i do not understand why this exception causes Test 2 to fail.

import { async } from '@angular/core/testing';
import { defer } from 'rxjs';

describe('Testsuit', () => {

  beforeEach(async(() => {
    // Test does succeed without async wrap, but i need the async wrap
    // to use the following line!
    // TestBed.configureTestingModule({}).compileComponents();
  }));

  it('Test 1', () => {
    defer(() => Promise.resolve()).subscribe(() => {
      throw new Error('WTF!');
    });
  });

  it('Test 2', () => {
    expect(true).toBeTruthy();
  });
});

Output

enter image description here

Aucun commentaire:

Enregistrer un commentaire