-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
52 lines (41 loc) · 1.83 KB
/
test.js
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
import test from 'ava';
import setUrlParameter from './setUrlParameter';
test('should return undefinded if no arguments are passed', t => {
const urlWithNewParam = setUrlParameter();
t.is(urlWithNewParam, undefined);
});
test('should add new parameter to URL with no existing parameter', t => {
const url = 'https://www.example.com/index.html';
let key = 'eee';
const value = 'fff';
const urlWithNewParam = setUrlParameter(url, key, value);
t.is(urlWithNewParam, 'https://www.example.com/index.html?eee=fff');
});
test('should add new parameter to URL with existing parameter', t => {
const url = 'https://www.example.com/index.html?aaa=bbb&ccc=ddd';
let key = 'eee';
const value = 'fff';
const urlWithNewParam = setUrlParameter(url, key, value);
t.is(urlWithNewParam, 'https://www.example.com/index.html?aaa=bbb&ccc=ddd&eee=fff');
});
test('should replace parameter to URL with existing parameter', t => {
const url = 'https://www.example.com/index.html?aaa=bbb&ccc=ddd';
let key = 'aaa';
const value = 'fff';
const urlWithNewParam = setUrlParameter(url, key, value);
t.is(urlWithNewParam, 'https://www.example.com/index.html?aaa=fff&ccc=ddd');
});
test('should add special character parameter to URL with existing parameter and decode it', t => {
const url = 'https://www.example.com/index.html';
let key = '🎿';
const value = '⛷';
const urlWithNewParam = setUrlParameter(url, key, value);
t.is(urlWithNewParam, 'https://www.example.com/index.html?%F0%9F%8E%BF=%E2%9B%B7');
});
test('should replace special character parameter to URL with existing parameter and decode it', t => {
const url = 'https://www.example.com/index.html?%F0%9F%8E%BF=%E2%9B%B7';
let key = '🎿';
const value = 'test';
const urlWithNewParam = setUrlParameter(url, key, value);
t.is(urlWithNewParam, 'https://www.example.com/index.html?%F0%9F%8E%BF=test');
});