Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test an input with ng-model-option debounce?

I have an input with ng-model-options="{debounce:250}"

and say I have a ng-change on the element and spy on that function. now if I do a simple test of the input like:

it('test', function(){
  input.val('hello');

  expect(ngChangeSpy).toHaveBeenCalledWith('hello');
})

obviously this doesn't work. I've seen you can wait for promises to resolve and such, but here I just want to wait 250 milliseconds in order for the model to change. Is there a way to achieve this?

like image 656
Gustav Avatar asked Nov 09 '22 20:11

Gustav


1 Answers

You can use $timeout.flush() https://docs.angularjs.org/api/ngMock/service/$timeout to flush your deferred functions if you don't want to test the 250ms delay.

like image 187
Jeroen Bastijns Avatar answered Nov 14 '22 21:11

Jeroen Bastijns