0

I'm trying to create a spy on Jquery that's making a call like:

$('#AccountNumber').val();

How would I set up the spy to return a value based on the #AccountNumber selector?

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
Korbin
  • 1,788
  • 2
  • 18
  • 29

1 Answers1

0

You could try this:

var spy = ('#AccountNumber', 'ValueChanged');
$('#AccountNumber').trigger('ValueChanged');
expect(spy).toHaveBeenTriggered();
var val = $(spy.selector).val();

Update after edit: You could add this - Watch for object properties changes in JavaScript then inside handler trigger event 'ValueChanged', and on spy add listener to that event.

Community
  • 1
  • 1
Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265