-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.spec.js
65 lines (55 loc) · 2.16 KB
/
index.spec.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
53
54
55
56
57
58
59
60
61
62
63
64
65
import getUrlParams from './index';
test('test location.href', () => {
expect(getUrlParams()).toEqual({
ie: 'utf-8',
f: '8',
rsv_bp: '1',
rsv_idx: '1',
tn: 'baidu',
wd: 'babel',
oq: 'babelHelpers',
rsv_pq: 'b9cc3c7700075933',
rsv_t: '8a81Gk9yDukgCvKLbKpmnbj1Qv+Wtwpj4aQWHC81apAMTWbacd77hPV3VE0',
rqlang: 'cn',
rsv_enter: '0',
inputT: '1994',
rsv_sug3: '44',
rsv_sug1: '41',
rsv_sug7: '100',
rsv_sug2: '0',
rsv_sug4: '2109',
rsv_sug: '1'
});
});
test('test browser router', () => {
let params = getUrlParams('https://www.buttercatann.com/promotion/?channel=zyxf_jg_pyq_5&id=1273733713');
expect(params).toEqual({ channel: 'zyxf_jg_pyq_5', id: '1273733713' });
params = getUrlParams('https://www.buttercatann.com/promotion/?channel=&id=123');
expect(params).toEqual({ channel: '', id: '123' });
});
test('test hash router', () => {
let params = getUrlParams('https://api.l-blog.me/appServer/preRegist/index.html#/?channel=HYJR');
expect(params).toEqual({ channel: 'HYJR' });
params = getUrlParams('https://www.buttercatann.com/promotion/?channel=zyxf_j#g_pyq_5&id=1273733713');
expect(params).toEqual({ channel: 'zyxf_j' });
});
test('no params', () => {
const params = getUrlParams('https://www.buttercatann.com/promotion/');
expect(params).toEqual({});
});
test('null string', () => {
expect(getUrlParams('')).toEqual({});
expect(getUrlParams(' ')).toEqual({});
expect(getUrlParams(null)).toEqual({});
let params = getUrlParams('https://www.buttercatann.com/promotion/?channel=zyxf_jg_pyq_5& &id=1273733713');
expect(params).toEqual({ channel: 'zyxf_jg_pyq_5', id: '1273733713' });
});
test('not string', () => {
expect(getUrlParams({})).toEqual({});
expect(getUrlParams([])).toEqual({});
expect(getUrlParams(8)).toEqual({});
});
test('repeat key', () => {
let params = getUrlParams('https://www.buttercatann.com/promotion/?channel=zyxf_jg_pyq_5&id=1273733713&channel=attack_value');
expect(params).toEqual({ channel: 'zyxf_jg_pyq_5', id: '1273733713' });
});