Sagie Sagie -4 years ago 132
Javascript Question

Expect not toThrow function with arguments - Jasmine

I have function that gets 3 arguments. I want to check that this function not throwing an error.
I did something like this:


The problem is
need to get argument. How can I send the arguments?

P.S I tried to pass it argument but I got error that
myFunc(arg1, arg2, arg3)
is not a function.

Answer Source

toThrow matcher requires function to be passed as argument to expect so you can simply wrap your function call in anonymous function:

expect(function() {
    myFunc(arg1, arg2, arg3);

You can also use bind to create new 'version' of your function that when called will be passed provided arguments:

expect(myFunc.bind(null, arg1, arg2, arg3)).not.toThrow();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download