Jasmine: Reset the location when testing code that uses pushState / replaceState

Updated . Posted . Visible to the public.

When testing code that uses pushState / replaceState, your browser will appear to navigate away from http://localhost:3000/specs (or wherever you run your Jasmine tests). This is inconvenient, since reloading the document will no longer re-run the test suite.

To remedy this, copy the attached file to a place like spec/javascripts/helpers and #= require it from your tests. It will store the current location before every test and reset if afterwards (using location.replaceState).

Henning Koch
Last edit
Henning Koch
Attachments
Keywords
javascript
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2015-01-17 18:33)