How do I mock window object? I'm doing firefox extension and I want to use jasmine for javascript testing.
In my javascript I have
function submit() {
...
var url = window.arguments[0];
...
}
Obviously, I have to mock window.arguments[0] in jasmine because that object doesn't exists if not passing any parameter from window.openDialog
This is my attempt to mock it with "with"
it("should submit to server", function() {
var localContext = {
"window": {
arguments: ["http://localhost"]
}
}
with(localContext);
But I still get this error TypeError: Cannot read property '0' of undefined, it's like when the test is run window.arguments[0] gets wiped out with the real window, because if I do
window.arguments[0]
inside the test, it prints out "http://localhost" correctly. but when it comes to submit() method it shows the error that window.argument is undefined.