I want to test a function that reloads a web page:
loadLocale = function (locale) {
window.location = window.location.href + "?locale=" + locale;
}
With Jasmine I would think that this would work:
describe("loadLocale", function () {
it("loads the current page with a given locale", function () {
loadLocale("en");
expect(window.location.search).toEqual("?locale=en");
});
});
But I get a stack overflow:
js: exception from uncaught JavaScript throw: java.lang.StackOverflowError
Any ideas on how to test this?
Yours,
Trevor
--
Trevor Lalish-Menagh
tr...@trevmex.com
484.868.6150 (mobile)
trevmex (AIM)
--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To post to this group, send email to jasmi...@googlegroups.com.
To unsubscribe from this group, send email to jasmine-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jasmine-js?hl=en.
> Any ideas on how to test this?
I normally make a function like this:
window.redirect = function(destination) {
window.location = destination;
}
which I don't test with Jasmine. Then I'll use that in my production
code instead of setting window.location directly, and make a spy for
it in my tests.
-- Erik
One thing you can do though, is let your code modify
window.location, only using inpage anchors. Remember setting
"window.location = "#inpageAnchor" won't actually navigate the
browser, just scroll to the <a name?="inpageAnchor"> if its there.
Your code should probably be configurable to target a particular
server, configure it to use (window.location + "#/") as the current
server, then set your expectations against window.location (trimming
left on the #).