Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jasmine - how to check if an argument exists?

Tags:

jasmine

good day.

im testing to see function got all her args.

i know what value two of her args must have,

but for the third arg, i just want to test if it exists.

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

thanks in advance

like image 216
adam Avatar asked Feb 14 '13 10:02

adam


1 Answers

You can also use jasmine.any. In case 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) and so on. From Jasmine doc:

jasmine.any takes a constructor or “class” name as an expected value. It returns true if the constructor matches the constructor of the actual value.

like image 132
zbynour Avatar answered Jan 01 '23 15:01

zbynour