1

In my code I throw message:

var err = new Error();
func1: function(){
        err.name = "error1";  
        throw(err);
    },

I tried to catch this error in Jasmine in two options:

expect(func1().toThrow("error1");
expect(func1().toThrow(new Error("error1"))

The problem that Jasmine failed and don't check this error. Did I miss something ?

Colin Brock
  • 21,267
  • 9
  • 46
  • 61
user1365697
  • 5,819
  • 15
  • 60
  • 96
  • To pass arguments to the function being tested, without using an anonymous function, try `Function.bind`: http://stackoverflow.com/a/13233194/294855 – Danyal Aytekin Nov 05 '12 at 14:54

1 Answers1

2

toThrow matches on the message field of the exception.

So, if you change your code to

func1: function(){
     err.message = "error1";  
     throw(err);
}

You should have more luck

Dancrumb
  • 26,597
  • 10
  • 74
  • 130