Laur's blog
  • Home
  • About
  • Support my work
Sign in Subscribe

throw

A collection of 1 post
Use "toThrowError" and "toThrow" in TypeScript with Objects
jasmine

Use "toThrowError" and "toThrow" in TypeScript with Objects

TL;DR: wrap your method call in the expect() statement. Instead of expect(obj.method()).toThrow(), write expect( () => { obj.method() }).toThrow(). While in the process of improving the code coverage, I needed to write a test for a method throwing an exception. My initial code would have been something
Mar 2, 2017 1 min read
Page 1 of 1
Laur's blog © 2025
  • Sign up
Powered by Ghost