Expect not toThrow function with arguments - Jasmine

Sagie :

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

expect(myFunc).not.toThrow();

The problem is myFunc need to get arguments. 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.

Bartek Fryzowicz :

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);
}).not.toThrow();

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();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Jasmine throws error on expect().toThrow instead of identifying the thrown error

Jasmine .toThrow error

Jasmine toThrow() syntax

Jasmine 'expect(...).withContext is not a function' error

Jasmine-marbles - Is there a expect(...).ToHaveBeenCalledWithObservable(...) function?

Can you write async tests that expect toThrow?

angular resource promise catch, jasmine toThrow()

How to get the number of arguments a function in a table expect?

Angular6 Jasmine TypeError: expect(...).toBeVisible is not a function

Use jasmine to expect that a function has been assigned to a variable?

How to hide error message from Jasmine expect function

Jasmine expect logic (expect A OR B)

How to expect error when parsing through arguments? - Angular6, Jasmine

Jasmine Expect toMatch and Parentheses

jasmine help, expect not working

Jasmine expect not working with requirejs

node: using chai's expect.to.throw on a function that takes arguments

Jasmine-node expect not executed

Jasmine spy "expect(xxx).notToHaveBeenCalled()

Angular Jasmine - expect().toHaveBeenCalled() not working

Jasmine multi expect per spec vs single expect per spec

minitest - mock - expect keyword arguments

How to pass variable arguments to expect

Why is jasmine-expect not validating that an error was thrown?

Jasmine `expect` never wrong in superagent `end`

Stop jasmine test after first expect fails

Expect jasmine Spy to be called "eventually", before timeout

Jasmine: Expect does not get actual value

Jasmine date expect always returning false