1

I want to do unit testing for DOM manipulation. Here is my scenario. I triggered the form reset by triggering the Click action of button using it's ID

document.getElementById('edit-reset').click();

I tried to perform unit testing, this is my try but not sure whether it's correct

var DOM = document.getElementById('edit-reset');
spyOn(document, 'getElementById').and.returnValue(true);
DOM.click();
expect(document.getElementById).toHaveBeenCalledWith('edit-reset');

Using jasmine and karma for UNIT testing Application is built on IONIC - Angular JS.

Help Appreciated ,How we can do unit testing for the above code in angularjs using jasmine?

Thanks!

yorch
  • 7,170
  • 8
  • 32
  • 38
  • May be this will help in karma and phantomjs http://stackoverflow.com/questions/29806153/calling-click-function-on-html-element-in-jasmine-phantomjs-test – ChennaiDrupalist Mar 15 '16 at 03:37
  • Your test does not make sense, if you were trying to detect if `getElementById` was called when you trigger `DOM.click()`, it's never going to happen, `click` won't trigger it. If on the other side, you want to make sure that your first line `var DOM = document.getElementById('edit-reset')` actually calls `getElementById`, you would need to put the `spyOn` before that line, but wouldn't make sense to test that. – yorch Mar 15 '16 at 04:39

0 Answers0