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
  • 67,326
  • 35
  • 140
  • 172
Korbin
  • 1,768
  • 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
  • 54,146
  • 29
  • 227
  • 241