How to write a test which expects an Error to be thrown in Jasmine?

前端 未结 9 1107
忘了有多久
忘了有多久 2020-11-28 17:26

I\'m trying to write a test for the Jasmine Test Framework which expects an error. At the moment I\'m using a Jasmine Node.js integration from GitHub.

In my Node mod

9条回答
  •  孤街浪徒
    2020-11-28 18:14

    I know that is more code but you can also do:

    try
       do something
       @fail Error("should send a Exception")
     catch e
       expect(e.name).toBe "BLA_ERROR"
       expect(e.message).toBe 'Message'
    

提交回复
热议问题