Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jasmine toHaveBeenCalledWith partial matching

With Jasmine, I could spy on methods and figure out the arguments. I want to be able to call toHaveBeenCalledWith(something, anything).

Let's say I want to spy on a method .on(event, callback). All I care about is if the event is listened to rather than what the actual callback identity is. Is it possible to do this without writing a custom matcher? I don't see one.

like image 490
Pwnna Avatar asked Jan 13 '14 20:01

Pwnna


2 Answers

Try

toHaveBeenCalledWith(jasmine.any(Object), jasmine.any(Function))
like image 148
beautifulcoder Avatar answered Oct 09 '22 11:10

beautifulcoder


Jasmine 2:

 expect(callback).toHaveBeenCalledWith(jasmine.objectContaining({
    bar: "baz"
  }));

https://jasmine.github.io/2.0/introduction.html

like image 53
Ievgen Martynov Avatar answered Oct 09 '22 11:10

Ievgen Martynov