jeudi 3 mars 2016

Test if an exception was catched in Jasmine

How do I test if an exception was catched in Jasmine?

The expectation is true if I remove the try...catch statement but I'm not interested on that.

Spec

import { foo } from './src';

describe('app', () => {
  it('should match if an exception was catched', () => {
    expect(() => foo()).toThrow();
  });
});

Source

function foo() {
  try {
    throw new Error();
  } catch(e) {
    console.log(e);
  }
}

export { foo };

Aucun commentaire:

Enregistrer un commentaire