forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils-spec.ts
More file actions
93 lines (83 loc) · 3.68 KB
/
Utils-spec.ts
File metadata and controls
93 lines (83 loc) · 3.68 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
92
93
import { IEvent } from './models/IEvent';
import { Utils } from 'Utils';
describe('Utils', () => {
it('should add range', () => {
var target:string[];
expect(Utils.addRange(target)).toEqual([]);
expect(target).toBeUndefined();
expect(Utils.addRange(target, '1', '2')).toEqual(['1', '2']);
expect(Utils.addRange(target, '1', '2')).toEqual(['1', '2']);
target = ['3'];
expect(Utils.addRange(target, '1', '2')).toEqual(['3', '1', '2']);
expect(target).toEqual(['3', '1', '2']);
});
it('should stringify circular reference', () => {
var afoo:any = {a: 'foo'};
afoo.b = afoo;
expect(Utils.stringify(afoo)).toBe('{"a":"foo"}');
expect(Utils.stringify([{one: afoo, two: afoo}])).toBe('[{"one":{"a":"foo"}}]');
});
it('should exclude properties', () => {
var user:any = {
id:1,
name: 'Blake',
password: '123456',
passwordResetToken: 'a reset token',
myPasswordValue: '123456',
myPassword: '123456',
customValue: 'Password',
value: {
Password: '123456'
}
};
expect(Utils.stringify(user)).toBe(JSON.stringify(user));
expect(Utils.stringify(user, ['pAssword'])).toBe('{"id":1,"name":"Blake","passwordResetToken":"a reset token","myPasswordValue":"123456","myPassword":"123456","customValue":"Password","value":{}}');
expect(Utils.stringify(user, ['*password'])).toBe('{"id":1,"name":"Blake","myPasswordValue":"123456","myPassword":"123456","customValue":"Password","value":{}}');
expect(Utils.stringify(user, ['password*'])).toBe('{"id":1,"name":"Blake","passwordResetToken":"a reset token","myPasswordValue":"123456","customValue":"Password","value":{}}');
expect(Utils.stringify(user, ['*password*'])).toBe('{"id":1,"name":"Blake","customValue":"Password","value":{}}');
});
it('should stringify array', () => {
var error = {
"type": "error",
"data": {
"@error": {
"type": "Error",
"message": "string error message",
"stack_trace": [
{
"name": "throwStringErrorImpl",
"parameters": [],
"file_name": "http://localhost/index.js",
"line_number": 22,
"column": 9
},
{
"name": "throwStringError",
"parameters": [],
"file_name": "http://localhost/index.js",
"line_number": 10,
"column": 10
}, {
"name": "HTMLButtonElement.onclick",
"parameters": [],
"file_name": "http://localhost/",
"line_number": 22,
"column": 10
}]
}, "@submission_method": "onerror"
},
"tags": []
};
expect(Utils.stringify(error)).toBe(JSON.stringify(error));
expect(Utils.stringify([error, error])).toBe(JSON.stringify([error, error]));
});
it('should parse version from url', () => {
expect(Utils.parseVersion('https://code.jquery.com/jquery-2.1.3.js')).toBe('2.1.3');
expect(Utils.parseVersion('//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css')).toBe('3.3.4');
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/1140/2.0/1140.css')).toBe('2.0');
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/Base64/0.3.0/base64.min.js')).toBe('0.3.0');
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/angular-google-maps/2.1.0-X.10/angular-google-maps.min.js')).toBe('2.1.0-X.10');
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/2.1.8-M1/swagger-ui.min.js')).toBe('2.1.8-M1');
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/BLAH/BLAH.min.js')).toBe(null);
});
});