samedi 16 septembre 2017

Angular 4 & Jasmine: test succeed when a promise does not return

Is it possible to write a Jasmine test that succeeds when a promise does not return? My spec looks like this:

it( 'should not call clearHistory.emit() when the historyHidden() method is called with an incorrect animation event', ( done ) => {
  component.clearHistory.subscribe( () => {
    expect( false ).toBeTruthy(); // should fail is promise resolved
    done();
  } );

  component.historyHidden( hideEvent ); 
  // if the proimse times out, I'd like the test to succeed
} );

I have thought about a try/catch or something, but thought there must be a more standard way to do this. Any ideas?

Aucun commentaire:

Enregistrer un commentaire