0

My code has a line:

 $("#divID select").val(0)

I've to write a unit test using Jasmine for this. I've set up the dom elements. Can I stub val and check whether it's called on this particular selector and called with 0 as argument?

Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
user2597100
  • 97
  • 1
  • 10

1 Answers1

0

I guess that you could spy the fn.val of jquery.

spyOn($.fn, 'val')

And just check if the val method was called.

expect($.fn.val).toHaveBeenCalled();

I don't know how jquery works inside but I guess that he use the fn.val for every instance.

Or just mock the instance like this:

var instance = $("#divID select");
spyOn(instance, 'val').and.callFake(function() {
  //your mock function here
});
Jesús Quintana
  • 1,803
  • 13
  • 18