Simply put, in the end, i want to grab the query string from the url and add it to my cookie.
I know how to get the cookie set and am using Vanilla JS for it.
However I want to use Jasmine to test all the wrong cases and not just the happy path.
Anyways, How does one set the url in Jasmine, so that I can pass any query string (like so that i can use it in my tests using
document.location.search
and take it from there?
I'm guessing whatever it is called when you mock in Jasmine, but if this was rails, i'd add a query string like:
test "can get some results" do
get :show, :q => shops(:one).name #how do i add this 'q' string in jasmine?!
refute_nil assigns(:search)
end
Simply put, in the end, i want to grab the query string from the url and add it to my cookie.
I know how to get the cookie set and am using Vanilla JS for it.
However I want to use Jasmine to test all the wrong cases and not just the happy path.
Anyways, How does one set the url in Jasmine, so that I can pass any query string (like http://www.blah.?ref=yayayadaydayday
so that i can use it in my tests using document.location.search
and take it from there?
I'm guessing whatever it is called when you mock in Jasmine, but if this was rails, i'd add a query string like:
test "can get some results" do
get :show, :q => shops(:one).name #how do i add this 'q' string in jasmine?!
refute_nil assigns(:search)
end
Share
Improve this question
asked Aug 1, 2012 at 20:34
pjammerpjammer
9,5875 gold badges47 silver badges56 bronze badges
2 Answers
Reset to default 3The problem is that you cant mock window.location
. In this and this SO they came up with passing the global context in you function so you can mock it.
I recently had to do something similar, testing some code for a set of tabs which selects a tab if the URL hash is set. I used the history API to manipulate the URL:
loadFixtures('tabs-fixtures.html');
window.history.replaceState(null, null, '#three');
and the code does indeed read the hash value from the URL.
my test setup uses PhantomJS. I imagine other browsers would work, unless you have an old IE launcher.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745359479a4624294.html
评论列表(0条)