mercredi 7 octobre 2015

Node JS Jasmine Testing multiple types with jasmine.any()

I'm using Jasmine (v2.2.0) for testing, and I'm trying to spy on a method which is expected to be called with specific data for the first argument, and unknown type for the second.

I'm familiar with spies and the .toHaveBeenCalledWith() syntax on spies, and joined with jasmine.any() it may look something like this:

expect(my.spy).toHaveBeenCalledWith('startMenu', jasmine.any(String));

But I'm unable to find a method to deal with several types. What I'm looking for is a method to perform the same action, where the second parameter is any type, and just as well, when the second param is one of some types, like:

// Any type is okay:
expect(my.spy).toHaveBeenCalledWith('startMenu', jasmine.any());

// String or number only:
expect(my.spy).toHaveBeenCalledWith('startMenu', jasmine.any(String OR Number));

Needless to mention, the previous examples are not working code, they are just what I'm looking for the correct syntax for.

Any kind of help is greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire