Reputation:
I have a javascript file that uses location.search
for some logic. I want to test it using Karma. When I simply set the location (window.location.search = 'param=value'
in the test), Karma complains I'm doing a full page reload. How do I pass a search parameter to my test?
Upvotes: 0
Views: 2012
Reputation: 2964
Without seeing some code it's a little tricky to know what you exactly want, however it sounds like you want some sort of fixture/mock capability added to your tests. If you check out this other answer to a very similar problem you will see that it tells you to keep the test as a "unit".
What this means is that we're not really concerned with testing the Window object, we'll assume Chrome or Firefox manufacturers will do this just fine for us. In your test you will be able to check and respond to your mock object and investigate that according to your logic. When running in live code - as shown - the final step of actually handing over the location is dealt with by the browser.
In other words you are just checking your location setting logic and no other functionality. I hope this can work for you.
Upvotes: 1