Jasmine - how to check if an argument exists?

a good day.

im testing to see that the function has received all its arguments.

I know the significance of her two arguments,

but for the third arg, I just want to check if it exists.

expect(myFunction).toHaveBeenCalledWithMatcher({
    a: 1,
    b: 2,
    c: dont know its val but want it to exist
});

early

+5
source share
2 answers

You can also use jasmine.any. If you expect a number, it could be:

expect(myFunction).toHaveBeenCalledWith({
    a: 1,
    b: 2,
    c: jasmine.any(Number)
});

It is also possible jasmine.any(Function), etc. From the Jasmine doc:

jasmine.any takes the name of the constructor or "class" as the expected value. It returns true if the constructor matches the constructor of the actual value.

+4
source

Try

  expect(myFunction.mostRecentCall.args[2]).toBeDefined();

and leave the argument in the toHaveBeenCalledWith test.

+4
source

All Articles