Restore history state after tests
We don't want to mess up anything permanent in each test or the tests might start affecting each other.
This commit is contained in:
parent
05b6d2ad67
commit
cd1a63b737
|
@ -8,39 +8,48 @@ describe('WebUtil', function () {
|
|||
"use strict";
|
||||
|
||||
describe('config variables', function () {
|
||||
let origState, origHref;
|
||||
beforeEach(function () {
|
||||
origState = history.state;
|
||||
origHref = location.href;
|
||||
});
|
||||
afterEach(function () {
|
||||
history.replaceState(origState, '', origHref);
|
||||
});
|
||||
|
||||
it('should parse query string variables', function () {
|
||||
// history.pushState() will not cause the browser to attempt loading
|
||||
// the URL, this is exactly what we want here for the tests.
|
||||
history.pushState({}, '', "test?myvar=myval");
|
||||
history.replaceState({}, '', "test?myvar=myval");
|
||||
expect(WebUtil.getConfigVar("myvar")).to.be.equal("myval");
|
||||
});
|
||||
it('should return default value when no query match', function () {
|
||||
history.pushState({}, '', "test?myvar=myval");
|
||||
history.replaceState({}, '', "test?myvar=myval");
|
||||
expect(WebUtil.getConfigVar("other", "def")).to.be.equal("def");
|
||||
});
|
||||
it('should handle no query match and no default value', function () {
|
||||
history.pushState({}, '', "test?myvar=myval");
|
||||
history.replaceState({}, '', "test?myvar=myval");
|
||||
expect(WebUtil.getConfigVar("other")).to.be.equal(null);
|
||||
});
|
||||
it('should parse fragment variables', function () {
|
||||
history.pushState({}, '', "test#myvar=myval");
|
||||
history.replaceState({}, '', "test#myvar=myval");
|
||||
expect(WebUtil.getConfigVar("myvar")).to.be.equal("myval");
|
||||
});
|
||||
it('should return default value when no fragment match', function () {
|
||||
history.pushState({}, '', "test#myvar=myval");
|
||||
history.replaceState({}, '', "test#myvar=myval");
|
||||
expect(WebUtil.getConfigVar("other", "def")).to.be.equal("def");
|
||||
});
|
||||
it('should handle no fragment match and no default value', function () {
|
||||
history.pushState({}, '', "test#myvar=myval");
|
||||
history.replaceState({}, '', "test#myvar=myval");
|
||||
expect(WebUtil.getConfigVar("other")).to.be.equal(null);
|
||||
});
|
||||
it('should handle both query and fragment', function () {
|
||||
history.pushState({}, '', "test?myquery=1#myhash=2");
|
||||
history.replaceState({}, '', "test?myquery=1#myhash=2");
|
||||
expect(WebUtil.getConfigVar("myquery")).to.be.equal("1");
|
||||
expect(WebUtil.getConfigVar("myhash")).to.be.equal("2");
|
||||
});
|
||||
it('should prioritize fragment if both provide same var', function () {
|
||||
history.pushState({}, '', "test?myvar=1#myvar=2");
|
||||
history.replaceState({}, '', "test?myvar=1#myvar=2");
|
||||
expect(WebUtil.getConfigVar("myvar")).to.be.equal("2");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue