-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
index.test.js
83 lines (59 loc) · 2.37 KB
/
index.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
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
/**
* Internal Dependencies
*/
import { addQueryArgs, prependHTTP } from '../';
describe( 'addQueryArgs', () => {
test( 'should append args to an URL without query string', () => {
const url = 'https://andalouses.example/beach';
const args = { sun: 'true', sand: 'false' };
expect( addQueryArgs( url, args ) ).toBe( 'https://andalouses.example/beach?sun=true&sand=false' );
} );
test( 'should append args to an URL with query string', () => {
const url = 'https://andalouses.example/beach?night=false';
const args = { sun: 'true', sand: 'false' };
expect( addQueryArgs( url, args ) ).toBe( 'https://andalouses.example/beach?night=false&sun=true&sand=false' );
} );
test( 'should update args to an URL with conflicting query string', () => {
const url = 'https://andalouses.example/beach?night=false&sun=false&sand=true';
const args = { sun: 'true', sand: 'false' };
expect( addQueryArgs( url, args ) ).toBe( 'https://andalouses.example/beach?night=false&sun=true&sand=false' );
} );
} );
describe( 'prependHTTP', () => {
test( 'should prepend http to a domain', () => {
const url = 'wordpress.org';
expect ( prependHTTP( url ) ).toBe( 'http:https://' + url );
} );
test( "shouldn't prepend http to an email", () => {
const url = '[email protected]';
expect ( prependHTTP( url ) ).toBe( url );
} );
test( "shouldn't prepend http to an absolute URL", () => {
const url = '/wordpress';
expect ( prependHTTP( url ) ).toBe( url );
} );
test( "shouldn't prepend http to a relative URL", () => {
const url = './wordpress';
expect ( prependHTTP( url ) ).toBe( url );
} );
test( "shouldn't prepend http to an anchor URL", () => {
const url = '#wordpress';
expect ( prependHTTP( url ) ).toBe( url );
} );
test( "shouldn't prepend http to a URL that already has http", () => {
const url = 'http:https://wordpress.org';
expect ( prependHTTP( url ) ).toBe( url );
} );
test( "shouldn't prepend http to a URL that already has https", () => {
const url = 'https://wordpress.org';
expect ( prependHTTP( url ) ).toBe( url );
} );
test( "shouldn't prepend http to a URL that already has ftp", () => {
const url = 'ftp:https://wordpress.org';
expect ( prependHTTP( url ) ).toBe( url );
} );
test( "shouldn't prepend http to a URL that already has mailto", () => {
const url = 'mailto:[email protected]';
expect ( prependHTTP( url ) ).toBe( url );
} );
} );