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
For coffeescript lovers
expect( => someMethodCall(arg1, arg2)).toThrow()
In my case the function throwing error was async so I followed here:
await expectAsync(asyncFunction()).toBeRejected();
await expectAsync(asyncFunction()).toBeRejectedWithError(...);
Try using an anonymous function instead:
expect( function(){ parser.parse(raw); } ).toThrow(new Error("Parsing is not possible"));
you should be passing a function into the expect(...)
call. Your incorrect code:
// incorrect:
expect(parser.parse(raw)).toThrow(new Error("Parsing is not possible"));
is trying to actually call parser.parse(raw)
in an attempt to pass the result into expect(...)
,