testaro 18.2.0 → 18.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/aslint/utils/aria.test.ts +12 -0
  2. package/aslint/utils/aria.ts +120 -0
  3. package/aslint/utils/async.test.ts +25 -0
  4. package/aslint/utils/async.ts +22 -0
  5. package/aslint/utils/common.test.ts +239 -0
  6. package/aslint/utils/common.ts +168 -0
  7. package/aslint/utils/console.test.ts +85 -0
  8. package/aslint/utils/console.ts +89 -0
  9. package/aslint/utils/css.test.ts +153 -0
  10. package/aslint/utils/css.ts +191 -0
  11. package/aslint/utils/dom.test.ts +627 -0
  12. package/aslint/utils/dom.ts +1051 -0
  13. package/aslint/utils/env.test.ts +14 -0
  14. package/aslint/utils/env.ts +8 -0
  15. package/aslint/utils/func.test.ts +160 -0
  16. package/aslint/utils/func.ts +70 -0
  17. package/aslint/utils/global.test.ts +12 -0
  18. package/aslint/utils/global.ts +25 -0
  19. package/aslint/utils/object.test.ts +524 -0
  20. package/aslint/utils/object.ts +278 -0
  21. package/aslint/utils/report.test.ts +56 -0
  22. package/aslint/utils/report.ts +36 -0
  23. package/aslint/utils/text.test.ts +270 -0
  24. package/aslint/utils/text.ts +165 -0
  25. package/aslint/utils/time.test.ts +43 -0
  26. package/aslint/utils/time.ts +33 -0
  27. package/package.json +1 -1
  28. package/procs/getSource.js +35 -0
  29. package/testaro/dupAtt.js +86 -108
  30. package/testaro/headEl.js +83 -0
  31. package/testaro/hrRisk.js +67 -0
  32. package/tests/testaro.js +2 -0
  33. package/validation/tests/jobs/headEl.json +67 -0
  34. package/validation/tests/jobs/hrRisk.json +134 -0
  35. package/validation/tests/targets/headEl/index.html +16 -0
  36. package/validation/tests/targets/hrRisk/index.html +18 -0
  37. /package/aslint/app/rules/aslint/{aria-role-dialog → redundant/aria-role-dialog}/aria-role-dialog.documentation.md +0 -0
  38. /package/aslint/app/rules/aslint/{aria-role-dialog → redundant/aria-role-dialog}/aria-role-dialog.test.ts +0 -0
  39. /package/aslint/app/rules/aslint/{aria-role-dialog → redundant/aria-role-dialog}/aria-role-dialog.ts +0 -0
  40. /package/aslint/app/rules/aslint/{capital-letters-words → redundant/capital-letters-words}/capital-letters-words.documentation.md +0 -0
  41. /package/aslint/app/rules/aslint/{capital-letters-words → redundant/capital-letters-words}/capital-letters-words.test.ts +0 -0
  42. /package/aslint/app/rules/aslint/{capital-letters-words → redundant/capital-letters-words}/capital-letters-words.ts +0 -0
  43. /package/aslint/app/rules/aslint/{contentinfo-landmark-only-one → redundant/contentinfo-landmark-only-one}/contentinfo-landmark-only-one.documentation.md +0 -0
  44. /package/aslint/app/rules/aslint/{contentinfo-landmark-only-one → redundant/contentinfo-landmark-only-one}/contentinfo-landmark-only-one.test.ts +0 -0
  45. /package/aslint/app/rules/aslint/{contentinfo-landmark-only-one → redundant/contentinfo-landmark-only-one}/contentinfo-landmark-only-one.ts +0 -0
  46. /package/aslint/app/rules/aslint/{empty-title-attribute → redundant/empty-title-attribute}/empty-title-attribute.documentation.md +0 -0
  47. /package/aslint/app/rules/aslint/{empty-title-attribute → redundant/empty-title-attribute}/empty-title-attribute.test.ts +0 -0
  48. /package/aslint/app/rules/aslint/{empty-title-attribute → redundant/empty-title-attribute}/empty-title-attribute.ts +0 -0
  49. /package/aslint/app/rules/aslint/{flash-content → redundant/flash-content}/flash-content.documentation.md +0 -0
  50. /package/aslint/app/rules/aslint/{flash-content → redundant/flash-content}/flash-content.test.ts +0 -0
  51. /package/aslint/app/rules/aslint/{flash-content → redundant/flash-content}/flash-content.ts +0 -0
  52. /package/aslint/app/rules/aslint/{font-style-italic → redundant/font-style-italic}/font-style-italic.documentation.md +0 -0
  53. /package/aslint/app/rules/aslint/{font-style-italic → redundant/font-style-italic}/font-style-italic.test.ts +0 -0
  54. /package/aslint/app/rules/aslint/{font-style-italic → redundant/font-style-italic}/font-style-italic.ts +0 -0
  55. /package/aslint/app/rules/aslint/{h1-must-be → redundant/h1-must-be}/h1-must-be.documentation.md +0 -0
  56. /package/aslint/app/rules/aslint/{h1-must-be → redundant/h1-must-be}/h1-must-be.test.ts +0 -0
  57. /package/aslint/app/rules/aslint/{h1-must-be → redundant/h1-must-be}/h1-must-be.ts +0 -0
  58. /package/aslint/app/rules/aslint/{aria-hidden-false → unimportant/aria-hidden-false}/aria-hidden-false.test.ts +0 -0
  59. /package/aslint/app/rules/aslint/{aria-hidden-false → unimportant/aria-hidden-false}/aria-hidden-false.ts +0 -0
  60. /package/aslint/app/rules/aslint/{aria-hidden-false → unimportant/aria-hidden-false}/aria-hidden.documentation.md +0 -0
  61. /package/aslint/app/rules/aslint/{content-editable-missing-attributes → unimportant/content-editable-missing-attributes}/content-editable-missing-attributes.docmentation.md +0 -0
  62. /package/aslint/app/rules/aslint/{content-editable-missing-attributes → unimportant/content-editable-missing-attributes}/content-editable-missing-attributes.test.ts +0 -0
  63. /package/aslint/app/rules/aslint/{content-editable-missing-attributes → unimportant/content-editable-missing-attributes}/content-editable-missing-attributes.ts +0 -0
  64. /package/aslint/app/rules/aslint/{elements-not-allowed-in-head → used/elements-not-allowed-in-head}/elements-not-allowed-in-head.documentation.md +0 -0
  65. /package/aslint/app/rules/aslint/{elements-not-allowed-in-head → used/elements-not-allowed-in-head}/elements-not-allowed-in-head.test.ts +0 -0
  66. /package/aslint/app/rules/aslint/{elements-not-allowed-in-head → used/elements-not-allowed-in-head}/elements-not-allowed-in-head.ts +0 -0
  67. /package/aslint/app/rules/aslint/{headings-sibling-unique → used/headings-sibling-unique}/headings-sibling-unique.documentation.md +0 -0
  68. /package/aslint/app/rules/aslint/{headings-sibling-unique → used/headings-sibling-unique}/headings-sibling-unique.test.ts +0 -0
  69. /package/aslint/app/rules/aslint/{headings-sibling-unique → used/headings-sibling-unique}/headings-sibling-unique.ts +0 -0
  70. /package/aslint/app/rules/aslint/{horizontal-rule → used/horizontal-rule}/horizontal-rule.documentation.md +0 -0
  71. /package/aslint/app/rules/aslint/{horizontal-rule → used/horizontal-rule}/horizontal-rule.test.ts +0 -0
  72. /package/aslint/app/rules/aslint/{horizontal-rule → used/horizontal-rule}/horizontal-rule.ts +0 -0
@@ -0,0 +1,524 @@
1
+ import { Global } from './global';
2
+ import { ObjectUtility } from './object';
3
+
4
+ describe('Utils', () => {
5
+ describe('ObjectUtility', () => {
6
+
7
+ it('should indicate that class exists', () => {
8
+ const objectUtility = new ObjectUtility();
9
+
10
+ expect(objectUtility).toBeDefined();
11
+ });
12
+
13
+ describe('#extend', () => {
14
+
15
+ it('should extend object A with B', () => {
16
+ const a = {
17
+ a: 1
18
+ };
19
+
20
+ const b = {
21
+ b: 1,
22
+ c: {
23
+ c: 1
24
+ }
25
+ };
26
+
27
+ ObjectUtility.extend(a, b);
28
+
29
+ // @ts-ignore
30
+ expect(a.b).toBe(1);
31
+ // @ts-ignore
32
+ expect(a.c.c).toBe(1);
33
+ });
34
+
35
+ it('should extend new object with specified object (deep copy)', () => {
36
+ const sourceObject = {
37
+ arr: [
38
+ {
39
+ example: 'example'
40
+ }
41
+ ],
42
+ date: new Date('2017-05-07'),
43
+ id: 1,
44
+ nodes: [
45
+ document.createElement('span')
46
+ ],
47
+ regexp: new RegExp(/test/),
48
+ str: 'str'
49
+ };
50
+
51
+ Object.defineProperty(sourceObject, 'notEnumerable', {
52
+ enumerable: false,
53
+ value: 'notEnumerable'
54
+ });
55
+
56
+ const extendedObject = ObjectUtility.extend({}, sourceObject);
57
+
58
+ extendedObject.id = 2;
59
+ extendedObject.arr[0].example = 'example2';
60
+ extendedObject.nodes[0] = document.createElement('div');
61
+ extendedObject.str = 'str2';
62
+ extendedObject.regexp = 'regexp';
63
+ extendedObject.date = 'date';
64
+
65
+ expect(sourceObject.id).toBe(1);
66
+ expect(sourceObject.arr[0].example).toBe('example');
67
+ expect(sourceObject.nodes[0].nodeName.toLowerCase()).toBe('span');
68
+ expect(sourceObject.str).toBe('str');
69
+ expect(Object.prototype.toString.call(sourceObject.regexp)).toBe('[object RegExp]');
70
+ expect(Object.prototype.toString.call(sourceObject.date)).toBe('[object Date]');
71
+ // @ts-ignore
72
+ expect(sourceObject.notEnumerable).toBe('notEnumerable');
73
+ expect(extendedObject.notEnumerable).toBeUndefined();
74
+ });
75
+
76
+ });
77
+
78
+ describe('#isHostObjectProperty', () => {
79
+
80
+ it('should test if the specified host object property references an object that is safe to evaluate', () => {
81
+ const o = {
82
+ method: () => {
83
+ }
84
+ };
85
+
86
+ const x = {
87
+ a: 1
88
+ };
89
+
90
+ expect(ObjectUtility.isHostObjectProperty(o, 'method')).toBeTruthy();
91
+ expect(ObjectUtility.isHostObjectProperty(x, 'a')).toBeFalsy();
92
+ });
93
+
94
+ });
95
+
96
+ describe('#isTypeOf', () => {
97
+
98
+ it('should return false if no arguments passed', () => {
99
+ expect(() => {
100
+ // @ts-ignore
101
+ ObjectUtility.isTypeOf();
102
+ }).toThrowError('[ObjectUtility.isTypeOf] requires two arguments');
103
+ });
104
+
105
+ it('should return true when object type undefined passed', () => {
106
+ const a = undefined;
107
+
108
+ expect(ObjectUtility.isTypeOf(a, 'undefined')).toBeTruthy();
109
+ });
110
+
111
+ it('should return true when object type function passed', () => {
112
+ expect(ObjectUtility.isTypeOf(() => {
113
+ }, 'function')).toBeTruthy();
114
+ });
115
+
116
+ it('should return true when object type number passed and it\'s type is passed in capital letters', () => {
117
+ expect(ObjectUtility.isTypeOf(1, 'NUMBER')).toBeTruthy();
118
+ });
119
+
120
+ it('should return true when object type nubmer passed', () => {
121
+ expect(ObjectUtility.isTypeOf(1, 'number')).toBeTruthy();
122
+ });
123
+
124
+ it('should return true object type null passed', () => {
125
+ expect(ObjectUtility.isTypeOf(null, 'null')).toBeTruthy();
126
+ });
127
+
128
+ it('should return true object type null passed', () => {
129
+ expect(ObjectUtility.isTypeOf(null, 'object')).toBeFalsy();
130
+ });
131
+
132
+ it('should return true when object type object passed', () => {
133
+ expect(ObjectUtility.isTypeOf({}, 'object')).toBeTruthy();
134
+ });
135
+
136
+ it('should return false when object type object passed, but check type is for string', () => {
137
+ expect(ObjectUtility.isTypeOf({}, 'string')).toBeFalsy();
138
+ });
139
+
140
+ it('should return true when object type array passed', () => {
141
+ expect(ObjectUtility.isTypeOf([], 'array')).toBeTruthy();
142
+ });
143
+
144
+ it('should return false when passed array, but checked for "object"', () => {
145
+ expect(ObjectUtility.isTypeOf([], 'object')).toBeFalsy();
146
+ });
147
+
148
+ it('should return true when object type string passed', () => {
149
+ expect(ObjectUtility.isTypeOf('test', 'string')).toBeTruthy();
150
+ expect(ObjectUtility.isTypeOf('', 'string')).toBeTruthy();
151
+ });
152
+
153
+ it('should return true when object type boolean passed', () => {
154
+ expect(ObjectUtility.isTypeOf(true, 'boolean')).toBeTruthy();
155
+ expect(ObjectUtility.isTypeOf(false, 'boolean')).toBeTruthy();
156
+ });
157
+
158
+ // ES6 feature (need this verification especially for PhantomJS)
159
+ if (ObjectUtility.isHostMethod(Global, 'Symbol')) {
160
+
161
+ it('should return true when object type symbol passed', () => {
162
+ expect(ObjectUtility.isTypeOf(Global.context.Symbol('foo'), 'symbol')).toBeTruthy();
163
+ });
164
+
165
+ }
166
+
167
+ });
168
+
169
+ describe('#getTypeOf', () => {
170
+
171
+ it('should return false if no arguments passed', () => {
172
+ expect(ObjectUtility.getTypeOf()).toBe('unknown');
173
+ });
174
+
175
+ it('should return "undefined" when object type undefined passed', () => {
176
+ const a = undefined;
177
+
178
+ expect(ObjectUtility.getTypeOf(a)).toBe('undefined');
179
+ });
180
+
181
+ it('should return "boolean" when object type boolean (false) passed', () => {
182
+ const a: boolean = false;
183
+
184
+ expect(ObjectUtility.getTypeOf(a)).toBe('boolean');
185
+ });
186
+
187
+ it('should return "boolean" when object type boolean (true) passed', () => {
188
+ const a: boolean = true;
189
+
190
+ expect(ObjectUtility.getTypeOf(a)).toBe('boolean');
191
+ });
192
+
193
+ it('should return "number" when object type number passed', () => {
194
+ expect(ObjectUtility.getTypeOf(1)).toBe('number');
195
+ });
196
+
197
+ it('should return "string" when object type string passed', () => {
198
+ expect(ObjectUtility.getTypeOf('test')).toBe('string');
199
+ });
200
+
201
+ it('should return "object" when object type object passed', () => {
202
+ expect(ObjectUtility.getTypeOf({})).toBe('object');
203
+ });
204
+
205
+ it('should return "null" when object type null passed', () => {
206
+ expect(ObjectUtility.getTypeOf(null)).toBe('null');
207
+ });
208
+
209
+ it('should return "array" when object type array passed', () => {
210
+ expect(ObjectUtility.getTypeOf([])).toBe('array');
211
+ });
212
+
213
+ it('should return "htmldivelement" when object type HTMLElement passed', () => {
214
+ expect(ObjectUtility.getTypeOf(document.createElement('div'))).toBe('htmldivelement');
215
+ });
216
+
217
+ // ES6 feature (need this verification especially for PhantomJS)
218
+ if (ObjectUtility.isHostMethod(Global, 'Symbol')) {
219
+
220
+ it('should return "symbol" when object type symbol passed', () => {
221
+ expect(ObjectUtility.getTypeOf(Global.context.Symbol('foo'))).toBe('symbol');
222
+ });
223
+
224
+ }
225
+
226
+ });
227
+
228
+ describe('#isNumber', () => {
229
+
230
+ it('should return true if object is a number type', () => {
231
+ expect(ObjectUtility.isNumber(-1)).toBeTruthy();
232
+ expect(ObjectUtility.isNumber(-1.1)).toBeTruthy();
233
+ expect(ObjectUtility.isNumber(-0.1)).toBeTruthy();
234
+ expect(ObjectUtility.isNumber(-0.1)).toBeTruthy();
235
+
236
+ expect(ObjectUtility.isNumber(1)).toBeTruthy();
237
+ expect(ObjectUtility.isNumber(1.1)).toBeTruthy();
238
+ expect(ObjectUtility.isNumber(0.1)).toBeTruthy();
239
+ expect(ObjectUtility.isNumber(0.1)).toBeTruthy();
240
+ expect(ObjectUtility.isNumber(0)).toBeTruthy();
241
+
242
+ expect(ObjectUtility.isNumber('0x1')).toBeTruthy();
243
+ });
244
+
245
+ it('should return true if numbers are passed as a string type', () => {
246
+ expect(ObjectUtility.isNumber('-1')).toBeTruthy();
247
+ expect(ObjectUtility.isNumber('-1.1')).toBeTruthy();
248
+ expect(ObjectUtility.isNumber('-0.1')).toBeTruthy();
249
+ expect(ObjectUtility.isNumber('-.1')).toBeTruthy();
250
+
251
+ expect(ObjectUtility.isNumber('1')).toBeTruthy();
252
+ expect(ObjectUtility.isNumber('1.1')).toBeTruthy();
253
+ expect(ObjectUtility.isNumber('0.1')).toBeTruthy();
254
+ expect(ObjectUtility.isNumber('.1')).toBeTruthy();
255
+ expect(ObjectUtility.isNumber('0.00')).toBeTruthy();
256
+ });
257
+
258
+ it('should return false if object is not a number type', () => {
259
+ expect(ObjectUtility.isNumber({})).toBeFalsy();
260
+ expect(ObjectUtility.isNumber([])).toBeFalsy();
261
+ expect(ObjectUtility.isNumber('')).toBeFalsy();
262
+ expect(ObjectUtility.isNumber('foo')).toBeFalsy();
263
+ expect(ObjectUtility.isNumber(false)).toBeFalsy();
264
+ expect(ObjectUtility.isNumber(true)).toBeFalsy();
265
+ });
266
+
267
+ });
268
+
269
+ // Enable after moving the isHtmlElement method from shared folder
270
+ describe('#isHtmlElement', () => {
271
+
272
+ it('should determine that tested element is HTML element', () => {
273
+ let el: Node | Element = document.createElement('div');
274
+
275
+ expect(ObjectUtility.isHtmlElement(el)).toBeTruthy();
276
+
277
+ el = document.createElement('circle');
278
+ expect(ObjectUtility.isHtmlElement(el)).toBeTruthy();
279
+
280
+ el = document.createElement('svg');
281
+ expect(ObjectUtility.isHtmlElement(el)).toBeTruthy();
282
+
283
+ el = document.createElement('body');
284
+ expect(ObjectUtility.isHtmlElement(el)).toBeTruthy();
285
+ });
286
+
287
+ it('should return false if passed text node type', () => {
288
+ const el = document.createTextNode('test');
289
+
290
+ expect(ObjectUtility.isHtmlElement(el)).toBeFalsy();
291
+ });
292
+
293
+ it('should return false if passed node not element type', () => {
294
+ const div = document.createTextNode('test');
295
+
296
+ expect(ObjectUtility.isHtmlElement(div)).toBeFalsy();
297
+ });
298
+
299
+ it('should return false when passed no argument', () => {
300
+ // @ts-ignore
301
+ expect(ObjectUtility.isHtmlElement()).toBeFalsy();
302
+ });
303
+
304
+ it('should return false when passed null as an argument', () => {
305
+ expect(ObjectUtility.isHtmlElement(null)).toBeFalsy();
306
+ });
307
+
308
+ it('should return false when passed Array as an argument', () => {
309
+ // @ts-ignore
310
+ expect(ObjectUtility.isHtmlElement([])).toBeFalsy();
311
+ });
312
+
313
+ it('should return false when passed Object with no properties as an argument', () => {
314
+ // @ts-ignore
315
+ expect(ObjectUtility.isHtmlElement([])).toBeFalsy();
316
+ });
317
+
318
+ });
319
+
320
+ describe('#deleteProperties', () => {
321
+
322
+ it('should remove all properties from object, except those that are in prototype chain', () => {
323
+ const o = Object.create(
324
+ {
325
+ a: 1
326
+ },
327
+ {
328
+ b: {
329
+ configurable: true,
330
+ enumerable: true,
331
+ value: 1,
332
+ writable: true
333
+ }
334
+ }
335
+ );
336
+
337
+ expect(Object.keys(ObjectUtility.deleteProperties(o)).length).toBe(0);
338
+ expect(Object.getPrototypeOf(o).a).toBe(1);
339
+ });
340
+
341
+ });
342
+
343
+ describe('#clearArray', () => {
344
+
345
+ it('should remove all items from array and keep the same array object', () => {
346
+
347
+ // @ts-ignore
348
+ const arr: [] = [1, 2, 3],
349
+ clearedArray = ObjectUtility.clearArray(arr);
350
+
351
+ expect(clearedArray.length).toBe(0);
352
+ expect(clearedArray === arr).toBeTruthy();
353
+ });
354
+
355
+ });
356
+
357
+ describe('#isNativeMethod', () => {
358
+
359
+ it('should determine that tested method is a native, built-in method', () => {
360
+ expect(ObjectUtility.isNativeMethod(String.prototype.trim)).toBeTruthy();
361
+ });
362
+
363
+ it('should determine that tested method is not a native, built-in method', () => {
364
+ const s: string = 'test';
365
+
366
+ expect(ObjectUtility.isNativeMethod(s)).toBeFalsy();
367
+ });
368
+
369
+ });
370
+
371
+ describe('#getProperty', () => {
372
+
373
+ it('should return null if value for the object with specified property does not exists', () => {
374
+ const o = {};
375
+
376
+ expect(ObjectUtility.getProperty(o, 'just.another.property')).toBeUndefined();
377
+ });
378
+
379
+ it('should return value if specified object property does exists', () => {
380
+ const o = {
381
+ test: {
382
+ hello: '1'
383
+ }
384
+ };
385
+
386
+ expect(ObjectUtility.getProperty(o, 'test.hello')).toEqual('1');
387
+ });
388
+
389
+ });
390
+
391
+ describe('#setProperty', () => {
392
+
393
+ it('should set value for the object with specified property defined as a string with dots', () => {
394
+ const o = {};
395
+
396
+ ObjectUtility.setProperty(o, 'just.another.property', true);
397
+
398
+ expect(o).toEqual(expect.objectContaining({
399
+ just: {
400
+ another: {
401
+ property: true
402
+ }
403
+ }
404
+ }));
405
+ });
406
+
407
+ it('should return null if passed object is not type object or array', () => {
408
+ expect(ObjectUtility.setProperty(false, 'just.another.property', true)).toBe(null);
409
+ expect(ObjectUtility.setProperty('', 'just.another.property', true)).toBe(null);
410
+ expect(ObjectUtility.setProperty(1, 'just.another.property', true)).toBe(null);
411
+ });
412
+
413
+ it('should return null if passed key as a non-string type', () => {
414
+ // @ts-ignore
415
+ expect(ObjectUtility.setProperty({})).toBe(null);
416
+ });
417
+
418
+ });
419
+
420
+ describe('#clone', () => {
421
+
422
+ it('should clone array without mutations on original array', () => {
423
+ const arr = [1],
424
+ cloned = arr.slice(0);
425
+
426
+ expect(cloned[0]).toBe(1);
427
+
428
+ cloned[0] = 2;
429
+
430
+ expect(cloned[0]).toBe(2);
431
+ expect(arr[0]).toBe(1);
432
+ });
433
+
434
+ it('should return cloned object without mutation original object #1', () => {
435
+ const o = {
436
+ a: 1,
437
+ b: {
438
+ z: 'b'
439
+ },
440
+ c: 'test',
441
+ d: [1],
442
+ e: true,
443
+ f: new Date('2017-05-07'),
444
+ g: new RegExp(/test/),
445
+ h: [
446
+ document.createElement('div')
447
+ ]
448
+ };
449
+ const oldDate: number = o.f.getDate();
450
+ const cloned = ObjectUtility.clone(o);
451
+
452
+ cloned.a = 2;
453
+ cloned.b.z = 2;
454
+ cloned.c = 'test2';
455
+ cloned.d[0] = 2;
456
+ cloned.e = false;
457
+ cloned.f.setDate('6');
458
+ cloned.g = 'removed RegExp';
459
+
460
+ expect(o.a).toBe(1);
461
+ expect(o.b.z).toBe('b');
462
+ expect(o.c).toBe('test');
463
+ expect(o.d[0]).toBe(1);
464
+ expect(o.e).toBe(true);
465
+ expect(o.f.getDate()).toBe(oldDate);
466
+ expect(Object.prototype.toString.call(o.g)).toBe('[object RegExp]');
467
+ /*
468
+ * TODO: find out why it returns [object Object]
469
+ * expect(Object.prototype.toString.call(cloned.h[0])).toBe('[object HTMLDivElement]');
470
+ */
471
+ });
472
+
473
+ it('should return cloned object without mutation original object #2', () => {
474
+ const o = {
475
+ id: 1,
476
+ impact: 'major',
477
+ links: [
478
+ {
479
+ content: 'content',
480
+ url: 'url'
481
+ }
482
+ ],
483
+ message: 'message',
484
+ nodes: [
485
+ document.createElement('span')
486
+ ],
487
+ ruleId: 'ruleId',
488
+ title: 'title',
489
+ type: 'type'
490
+ };
491
+
492
+ const cloned = ObjectUtility.clone(o);
493
+
494
+ expect(Object.prototype.toString.call(cloned.links).slice(8, -1)
495
+ .toLowerCase()).toBe('array');
496
+
497
+ expect(Object.prototype.toString.call(cloned.nodes).slice(8, -1)
498
+ .toLowerCase()).toBe('array');
499
+
500
+ cloned.id = 2;
501
+ cloned.impact = 'minor';
502
+ cloned.links[0].content = 'content2';
503
+ cloned.links[0].url = 'url2';
504
+ cloned.message = 'message2';
505
+ cloned.nodes[0] = document.createElement('div');
506
+ cloned.ruleId = 'ruleId2';
507
+ cloned.title = 'title2';
508
+ cloned.type = 'type2';
509
+
510
+ expect(o.id).toBe(1);
511
+ expect(o.impact).toBe('major');
512
+ expect(o.links[0].content).toBe('content');
513
+ expect(o.links[0].url).toBe('url');
514
+ expect(o.message).toBe('message');
515
+ expect(o.nodes[0].nodeName.toLowerCase()).toBe('span');
516
+ expect(o.ruleId).toBe('ruleId');
517
+ expect(o.title).toBe('title');
518
+ expect(o.type).toBe('type');
519
+ });
520
+
521
+ });
522
+
523
+ });
524
+ });