summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2023-04-06 17:49:44 +0200
committerPierre Ossman <ossman@cendio.se>2023-05-10 12:25:46 +0200
commitcd1a63b737b1ffa0fb5a343de7381bedf562c5e4 (patch)
tree26175340976811504af1fc26a49651c4a4fecc70
parent05b6d2ad67fbe6f3a7d7cbf1fbe0e0cec1362929 (diff)
downloadnovnc-cd1a63b737b1ffa0fb5a343de7381bedf562c5e4.tar.gz
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.
-rw-r--r--tests/test.webutil.js25
1 files changed, 17 insertions, 8 deletions
diff --git a/tests/test.webutil.js b/tests/test.webutil.js
index 76aa763..6f460a3 100644
--- a/tests/test.webutil.js
+++ b/tests/test.webutil.js
@@ -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");
});
});