assert-throws-with-message.ts 430 B

12345678910111213
  1. /**
  2. * Helper method for creating tests which assert a given error message when the operation is attempted.
  3. */
  4. export function assertThrowsWithMessage(operation: () => Promise<any>, message: string) {
  5. return async () => {
  6. try {
  7. await operation();
  8. fail('Should have thrown');
  9. } catch (err) {
  10. expect(err.message).toEqual(expect.stringContaining(message));
  11. }
  12. };
  13. }