I have javascript code that raises an alert if it's being run in the browser, but which I don't want to raise alerts when I run unit tests.
I tried to solve this by having a line
if( allowAlerts === false ){
alert = console.log;
}
but when I then run
alert("This bad thing happened");
I get back
TypeError: Illegal invocation
directly reassigning alert was a kludgey solution, and I can easily solve the problem in other ways, but I've never come across an illegal invocation error before and was hoping someone could explain what it means.