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?
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?
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
});