This repository was archived by the owner on Feb 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurlParameterHandler-test.js
More file actions
93 lines (61 loc) · 2.27 KB
/
Copy pathurlParameterHandler-test.js
File metadata and controls
93 lines (61 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//using tape to test: here's an articel I read through before doing this: https://ponyfoo.com/articles/testing-javascript-modules-with-tape
const test = require('tape');
const urlParameter = require('./urlParameterHandler');
var tapSpec = require('tap-spec');
test.createStream()
.pipe(tapSpec())
.pipe(process.stdout);
var windowMock = (function(){
var currentPathname = '';
var pathname = '';
var pushState = function(stateObj, windowTitle, location){
currentPathname = location;
}
return {
history: {
pushState: pushState
},
currentPathname: currentPathname,
pathname: pathname
}
}());
test('The Handler: config changes', function(t){
var configResult = urlParameter.config({
debounceTime: 1,
windowReplacement: windowMock
});
t.ok(configResult, 'Setting config option');
t.end();
});
test('The Handler: basic functions', function(t){
//queryString = ''
t.equal(urlParameter.set('1', '1', true), '?1=1', 'Add to blank');
//queryString = '?1=1'
t.equal(urlParameter.set('2', '2', true), '?1=1&2=2', 'Add to existing');
//query string = '?1=1&2=2'
t.equal(urlParameter.get('1', true), '1', 'Get from 1');
//query string still = '?1=1&2=2'
t.equal(urlParameter.set('1', '', true), '?2=2', 'Clear from multiple');
//query string = '?2=2'
t.equal(urlParameter.set('2', '', true), '', 'Clear 1');
//query string = ''
t.end();
});
test('The Handler: debounced change', function(t){
t.plan(1);
urlParameter.set('debounce', 'hasrun', true);
setTimeout(function () {
t.equal(urlParameter.getLiveQueryString(), '?debounce=hasrun', 'Debounced Set');
}, 1000);
});
// test('The Handler: should fail', function(t){
// t.notOk(urlParameter.set(), 'Set with no args');
// t.notOk(urlParameter.set(null, null, null, null), 'Set with nulls');
// t.notOk(urlParameter.set(undefined, undefined, undefined, undefined), 'Set with undefineds');
// t.notOk(urlParameter.set({}, {}, {}, {}), 'Set with empty objects');
// t.notOk(urlParameter.get(), 'Get with no args');
// t.notOk(urlParameter.get(null, null, null, null), 'Get with nulls');
// t.notOk(urlParameter.get(undefined, undefined, undefined, undefined), 'Get with undefineds');
// t.notOk(urlParameter.get({}, {}, {}, {}), 'Get with empty objects');
// t.end();
// });