I have 3 tests, each testing various methods.
it('test function1', function() {
spyOn(document, 'getElementById');
// ... some code to test function1
expect(document.getElementById).toHaveBeenCalled();
});
it('test function2', function() {
spyOn(document, 'getElementById');
// ... some code to test function2
expect(document.getElementById).toHaveBeenCalled();
});
it('test function3', function() {
spyOn(document, 'getElementById');
// ... some code to test function3
expect(document.getElementById).toHaveBeenCalled();
});
But when I run these tests I get the following error: getElementById has already been spied upon
. Can someone explain why am I getting this error even when spies are in different test suites and how to fix it.
document.getElementById('').style
etc in js file will throw error. – Duncan