@instructure/ui-utils 8.52.1-snapshot-6 → 8.52.1-snapshot-7

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 (59) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/es/__new-tests__/camelize.test.js +40 -0
  3. package/es/__new-tests__/cloneArray.test.js +52 -0
  4. package/es/__new-tests__/createChainedFunction.test.js +50 -0
  5. package/es/__new-tests__/generateId.test.js +60 -0
  6. package/es/__new-tests__/hash.test.js +415 -0
  7. package/es/__new-tests__/mergeDeep.test.js +196 -0
  8. package/es/__new-tests__/ms.test.js +40 -0
  9. package/es/__new-tests__/parseUnit.test.js +69 -0
  10. package/es/__new-tests__/pascalize.test.js +48 -0
  11. package/es/__new-tests__/px.test.js +51 -0
  12. package/es/__new-tests__/within.test.js +41 -0
  13. package/lib/__new-tests__/camelize.test.js +43 -0
  14. package/lib/__new-tests__/cloneArray.test.js +55 -0
  15. package/lib/__new-tests__/createChainedFunction.test.js +52 -0
  16. package/lib/__new-tests__/generateId.test.js +63 -0
  17. package/lib/__new-tests__/hash.test.js +417 -0
  18. package/lib/__new-tests__/mergeDeep.test.js +198 -0
  19. package/lib/__new-tests__/ms.test.js +42 -0
  20. package/lib/__new-tests__/parseUnit.test.js +71 -0
  21. package/lib/__new-tests__/pascalize.test.js +50 -0
  22. package/lib/__new-tests__/px.test.js +53 -0
  23. package/lib/__new-tests__/within.test.js +43 -0
  24. package/package.json +6 -5
  25. package/src/__new-tests__/camelize.test.tsx +42 -0
  26. package/src/__new-tests__/cloneArray.test.tsx +62 -0
  27. package/src/__new-tests__/createChainedFunction.test.tsx +54 -0
  28. package/src/__new-tests__/generateId.test.tsx +69 -0
  29. package/src/__new-tests__/hash.test.tsx +547 -0
  30. package/src/__new-tests__/mergeDeep.test.tsx +133 -0
  31. package/src/__new-tests__/ms.test.tsx +44 -0
  32. package/src/__new-tests__/parseUnit.test.tsx +80 -0
  33. package/src/__new-tests__/pascalize.test.tsx +51 -0
  34. package/src/__new-tests__/px.test.tsx +59 -0
  35. package/src/__new-tests__/within.test.tsx +44 -0
  36. package/tsconfig.build.json +0 -3
  37. package/tsconfig.build.tsbuildinfo +1 -1
  38. package/types/__new-tests__/camelize.test.d.ts +2 -0
  39. package/types/__new-tests__/camelize.test.d.ts.map +1 -0
  40. package/types/__new-tests__/cloneArray.test.d.ts +2 -0
  41. package/types/__new-tests__/cloneArray.test.d.ts.map +1 -0
  42. package/types/__new-tests__/createChainedFunction.test.d.ts +2 -0
  43. package/types/__new-tests__/createChainedFunction.test.d.ts.map +1 -0
  44. package/types/__new-tests__/generateId.test.d.ts +2 -0
  45. package/types/__new-tests__/generateId.test.d.ts.map +1 -0
  46. package/types/__new-tests__/hash.test.d.ts +2 -0
  47. package/types/__new-tests__/hash.test.d.ts.map +1 -0
  48. package/types/__new-tests__/mergeDeep.test.d.ts +2 -0
  49. package/types/__new-tests__/mergeDeep.test.d.ts.map +1 -0
  50. package/types/__new-tests__/ms.test.d.ts +2 -0
  51. package/types/__new-tests__/ms.test.d.ts.map +1 -0
  52. package/types/__new-tests__/parseUnit.test.d.ts +2 -0
  53. package/types/__new-tests__/parseUnit.test.d.ts.map +1 -0
  54. package/types/__new-tests__/pascalize.test.d.ts +2 -0
  55. package/types/__new-tests__/pascalize.test.d.ts.map +1 -0
  56. package/types/__new-tests__/px.test.d.ts +2 -0
  57. package/types/__new-tests__/px.test.d.ts.map +1 -0
  58. package/types/__new-tests__/within.test.d.ts +2 -0
  59. package/types/__new-tests__/within.test.d.ts.map +1 -0
@@ -0,0 +1,547 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import '@testing-library/jest-dom'
26
+ import { hash } from '../hash'
27
+
28
+ describe('hash', () => {
29
+ it('should error if supplied value is undefined', () => {
30
+ let error = false
31
+
32
+ try {
33
+ expect(hash(undefined)).toEqual('')
34
+ } catch (err: any) {
35
+ error = true
36
+ }
37
+
38
+ expect(error).toBe(true)
39
+ })
40
+
41
+ it('should allow specifying a max length', () => {
42
+ const result = hash('some value', 4)
43
+ expect(result).toBeDefined()
44
+ expect(result).toHaveLength(4)
45
+ })
46
+
47
+ describe('strings', () => {
48
+ it('hashes two identical strings to the same value', () => {
49
+ const result1 = hash('Some string with3_ distinct$() !_)(* va1ues')
50
+ const result2 = hash('Some string with3_ distinct$() !_)(* va1ues')
51
+
52
+ expect(result1).toBeDefined()
53
+ expect(result2).toBeDefined()
54
+
55
+ expect(result1).toEqual(result2)
56
+ })
57
+
58
+ it('hashes different strings to different values', () => {
59
+ const result1 = hash('Some string with3_ distinct$() !_)(* va1ues')
60
+ const result2 = hash('Some string with3_ distinct$() !_)(* va1ues ')
61
+
62
+ expect(result1).toBeDefined()
63
+ expect(result2).toBeDefined()
64
+
65
+ expect(result1).not.toEqual(result2)
66
+ })
67
+ })
68
+
69
+ describe('numbers', () => {
70
+ it('hashes two identical numbers to the same value', () => {
71
+ const result1 = hash(532)
72
+ const result2 = hash(532)
73
+
74
+ expect(result1).toBeDefined()
75
+ expect(result2).toBeDefined()
76
+
77
+ expect(result1).toEqual(result2)
78
+ })
79
+
80
+ it('hashes two different numbers to different values', () => {
81
+ const result1 = hash(532)
82
+ const result2 = hash(5321)
83
+
84
+ expect(result1).toBeDefined()
85
+ expect(result2).toBeDefined()
86
+
87
+ expect(result1).not.toEqual(result2)
88
+ })
89
+ })
90
+
91
+ describe('booleans', () => {
92
+ it('hashes true to the same value', () => {
93
+ const result1 = hash(true)
94
+ const result2 = hash(true)
95
+
96
+ expect(result1).toBeDefined()
97
+ expect(result2).toBeDefined()
98
+
99
+ expect(result1).toEqual(result2)
100
+ })
101
+
102
+ it('hashes false to the same value', () => {
103
+ const result1 = hash(false)
104
+ const result2 = hash(false)
105
+
106
+ expect(result1).toBeDefined()
107
+ expect(result2).toBeDefined()
108
+
109
+ expect(result1).toEqual(result2)
110
+ })
111
+
112
+ it('hashes true and false to different values', () => {
113
+ const result1 = hash(true)
114
+ const result2 = hash(false)
115
+
116
+ expect(result1).toBeDefined()
117
+ expect(result2).toBeDefined()
118
+
119
+ expect(result1).not.toEqual(result2)
120
+ })
121
+ })
122
+
123
+ describe('functions', () => {
124
+ it('hashes two identical arrow function expressions to the same value', () => {
125
+ const result1 = hash(() => 'foo')
126
+ const result2 = hash(() => 'foo')
127
+
128
+ expect(result1).toBeDefined()
129
+ expect(result2).toBeDefined()
130
+
131
+ expect(result1).toEqual(result2)
132
+ })
133
+
134
+ it('hashes two different arrow function expressions to different values', () => {
135
+ const result1 = hash(() => 'foo')
136
+ const result2 = hash(() => 'bar')
137
+
138
+ expect(result1).toBeDefined()
139
+ expect(result2).toBeDefined()
140
+
141
+ expect(result1).not.toEqual(result2)
142
+ })
143
+
144
+ it('hashes two identical functions to the same value', () => {
145
+ const result1 = hash(function myFunc() {
146
+ const foo = 1
147
+ const bar = 2
148
+ return foo + bar
149
+ })
150
+
151
+ const result2 = hash(function myFunc() {
152
+ const foo = 1
153
+ const bar = 2
154
+ return foo + bar
155
+ })
156
+
157
+ expect(result1).toBeDefined()
158
+ expect(result2).toBeDefined()
159
+
160
+ expect(result1).toEqual(result2)
161
+ })
162
+
163
+ it('hashes two identical functions with different names to different values', () => {
164
+ const result1 = hash(function myFunc() {
165
+ const foo = 1
166
+ const bar = 2
167
+ return foo + bar
168
+ })
169
+
170
+ const result2 = hash(function myFunc1() {
171
+ const foo = 1
172
+ const bar = 2
173
+ return foo + bar
174
+ })
175
+
176
+ expect(result1).toBeDefined()
177
+ expect(result2).toBeDefined()
178
+
179
+ expect(result1).not.toEqual(result2)
180
+ })
181
+
182
+ it('hashes two identical functions with different bodies to different values', () => {
183
+ const result1 = hash(function myFunc() {
184
+ const foo = 1
185
+ const bar = 2
186
+ return foo + bar
187
+ })
188
+
189
+ const result2 = hash(function myFunc() {
190
+ const foo = 1
191
+ const baz = 2
192
+ return foo + baz
193
+ })
194
+
195
+ expect(result1).toBeDefined()
196
+ expect(result2).toBeDefined()
197
+
198
+ expect(result1).not.toEqual(result2)
199
+ })
200
+ })
201
+
202
+ describe('objects', () => {
203
+ it('hashes two identical simple objects to the same value', () => {
204
+ const result1 = hash({
205
+ foo: 'foo',
206
+ bar: 'bar',
207
+ baz: 'baz'
208
+ })
209
+
210
+ const result2 = hash({
211
+ foo: 'foo',
212
+ bar: 'bar',
213
+ baz: 'baz'
214
+ })
215
+
216
+ expect(result1).toBeDefined()
217
+ expect(result2).toBeDefined()
218
+
219
+ expect(result1).toEqual(result2)
220
+ })
221
+
222
+ it('hashes two identical simple objects with rearranged keys to the same value', () => {
223
+ const result1 = hash({
224
+ foo: 'foo',
225
+ bar: 'bar',
226
+ baz: 'baz'
227
+ })
228
+
229
+ const result2 = hash({
230
+ baz: 'baz',
231
+ foo: 'foo',
232
+ bar: 'bar'
233
+ })
234
+
235
+ expect(result1).toBeDefined()
236
+ expect(result2).toBeDefined()
237
+
238
+ expect(result1).toEqual(result2)
239
+ })
240
+
241
+ it('hashes two different simple objects to different values', () => {
242
+ const result1 = hash({
243
+ foo: 'foo',
244
+ bar: 'bar',
245
+ baz: 'baz'
246
+ })
247
+
248
+ const result2 = hash({
249
+ foo: 'foo',
250
+ bar: 'ba',
251
+ baz: 'baz'
252
+ })
253
+
254
+ expect(result1).toBeDefined()
255
+ expect(result2).toBeDefined()
256
+
257
+ expect(result1).not.toEqual(result2)
258
+ })
259
+
260
+ it('hashes two identical complex objects to the same value', () => {
261
+ const result1 = hash({
262
+ foo: 'foo',
263
+ bar: [
264
+ {
265
+ qux: 'qux',
266
+ qang: 'qaz'
267
+ },
268
+ {
269
+ ['foo-bar']: true
270
+ }
271
+ ],
272
+ baz: () => {
273
+ const hello = 'hello'
274
+ const world = 'world'
275
+
276
+ return hello + world
277
+ }
278
+ })
279
+
280
+ const result2 = hash({
281
+ foo: 'foo',
282
+ bar: [
283
+ {
284
+ qux: 'qux',
285
+ qang: 'qaz'
286
+ },
287
+ {
288
+ ['foo-bar']: true
289
+ }
290
+ ],
291
+ baz: () => {
292
+ const hello = 'hello'
293
+ const world = 'world'
294
+
295
+ return hello + world
296
+ }
297
+ })
298
+
299
+ expect(result1).toBeDefined()
300
+ expect(result2).toBeDefined()
301
+
302
+ expect(result1).toEqual(result2)
303
+ })
304
+
305
+ it('hashes two identical complex objects with rearranged keys to the same value', () => {
306
+ const result1 = hash({
307
+ foo: 'foo',
308
+ bar: [
309
+ {
310
+ qux: 'qux',
311
+ qang: 'qaz'
312
+ },
313
+ {
314
+ ['foo-bar']: true
315
+ }
316
+ ],
317
+ baz: () => {
318
+ const hello = 'hello'
319
+ const world = 'world'
320
+
321
+ return hello + world
322
+ }
323
+ })
324
+
325
+ const result2 = hash({
326
+ bar: [
327
+ {
328
+ qux: 'qux',
329
+ qang: 'qaz'
330
+ },
331
+ {
332
+ ['foo-bar']: true
333
+ }
334
+ ],
335
+ foo: 'foo',
336
+ baz: () => {
337
+ const hello = 'hello'
338
+ const world = 'world'
339
+
340
+ return hello + world
341
+ }
342
+ })
343
+
344
+ expect(result1).toBeDefined()
345
+ expect(result2).toBeDefined()
346
+
347
+ expect(result1).toEqual(result2)
348
+ })
349
+
350
+ it('hashes two different simple objects to different values', () => {
351
+ const result1 = hash({
352
+ foo: 'foo',
353
+ bar: 'bar',
354
+ baz: 'baz'
355
+ })
356
+ const result2 = hash({
357
+ foo: 'foo',
358
+ bar: 'ba',
359
+ baz: 'baz'
360
+ })
361
+
362
+ expect(result1).toBeDefined()
363
+ expect(result2).toBeDefined()
364
+
365
+ expect(result1).not.toEqual(result2)
366
+ })
367
+
368
+ it('hashes two different complex objects to the same value', () => {
369
+ const result1 = hash({
370
+ foo: 'foo',
371
+ bar: [
372
+ {
373
+ qux: 'qux',
374
+ qang: 'qaz'
375
+ },
376
+ {
377
+ ['foobar']: true
378
+ }
379
+ ],
380
+ baz: () => {
381
+ const hello = 'hello'
382
+ const world = 'world'
383
+
384
+ return hello + world
385
+ }
386
+ })
387
+
388
+ const result2 = hash({
389
+ foo: 'foo',
390
+ bar: [
391
+ {
392
+ qux: 'qux',
393
+ qang: 'qaz'
394
+ },
395
+ {
396
+ ['foo-bar']: true
397
+ }
398
+ ],
399
+ baz: () => {
400
+ const hello = 'hello'
401
+ const world = 'world'
402
+
403
+ return hello + world
404
+ }
405
+ })
406
+
407
+ expect(result1).toBeDefined()
408
+ expect(result2).toBeDefined()
409
+
410
+ expect(result1).not.toEqual(result2)
411
+ })
412
+ })
413
+
414
+ describe('classes', () => {
415
+ it('hashes two identical classes to the same value', () => {
416
+ const result1 = hash(
417
+ class Something {
418
+ private _settings: number
419
+ constructor(settings: number) {
420
+ this._settings = settings
421
+ }
422
+
423
+ get settings() {
424
+ return this._settings
425
+ }
426
+
427
+ doSomething = () => {
428
+ return 'doing something'
429
+ }
430
+ }
431
+ )
432
+
433
+ const result2 = hash(
434
+ class Something {
435
+ private _settings: number
436
+ constructor(settings: number) {
437
+ this._settings = settings
438
+ }
439
+
440
+ get settings() {
441
+ return this._settings
442
+ }
443
+
444
+ doSomething = () => {
445
+ return 'doing something'
446
+ }
447
+ }
448
+ )
449
+
450
+ expect(result1).toBeDefined()
451
+ expect(result2).toBeDefined()
452
+
453
+ expect(result1).toEqual(result2)
454
+ })
455
+
456
+ it('hashes two classes with different content to different values', () => {
457
+ const result1 = hash(
458
+ class Something {
459
+ private _settings: number
460
+ constructor(settings: number) {
461
+ this._settings = settings
462
+ }
463
+ get settings() {
464
+ return this._settings
465
+ }
466
+
467
+ doSomething = () => {
468
+ return 'doing something'
469
+ }
470
+ }
471
+ )
472
+
473
+ const result2 = hash(
474
+ class Something {
475
+ private _settings: number
476
+ constructor(settings: number) {
477
+ this._settings = settings
478
+ }
479
+
480
+ get settings() {
481
+ return this._settings
482
+ }
483
+
484
+ doSomething = () => {
485
+ return 'doing something else'
486
+ }
487
+ }
488
+ )
489
+
490
+ expect(result1).toBeDefined()
491
+ expect(result2).toBeDefined()
492
+
493
+ expect(result1).not.toEqual(result2)
494
+ })
495
+
496
+ it('hashes two classes with different names to different values', () => {
497
+ const result1 = hash(
498
+ class Something {
499
+ private _settings: number
500
+ constructor(settings: number) {
501
+ this._settings = settings
502
+ }
503
+
504
+ get settings() {
505
+ return this._settings
506
+ }
507
+
508
+ doSomething = () => {
509
+ return 'doing something'
510
+ }
511
+ }
512
+ )
513
+
514
+ const result2 = hash(
515
+ class Somethin {
516
+ private _settings: number
517
+ constructor(settings: number) {
518
+ this._settings = settings
519
+ }
520
+
521
+ get settings() {
522
+ return this._settings
523
+ }
524
+
525
+ doSomething = () => {
526
+ return 'doing something'
527
+ }
528
+ }
529
+ )
530
+
531
+ expect(result1).toBeDefined()
532
+ expect(result2).toBeDefined()
533
+
534
+ expect(result1).not.toEqual(result2)
535
+ })
536
+
537
+ it('hashes null to the same value', () => {
538
+ const result1 = hash(null)
539
+ const result2 = hash(null)
540
+
541
+ expect(result1).toBeDefined()
542
+ expect(result2).toBeDefined()
543
+
544
+ expect(result1).toEqual(result2)
545
+ })
546
+ })
547
+ })
@@ -0,0 +1,133 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import '@testing-library/jest-dom'
26
+ import { mergeDeep } from '../mergeDeep'
27
+
28
+ describe('mergeDeep', () => {
29
+ it('should merge object properties without affecting any object', () => {
30
+ const obj1 = { a: 0, b: 1 }
31
+ const obj2 = { c: 2, d: 3 }
32
+ const obj3 = { a: 4, d: 5 }
33
+
34
+ const expected = { a: 4, b: 1, c: 2, d: 5 }
35
+
36
+ expect(mergeDeep({}, obj1, obj2, obj3)).toStrictEqual(expected)
37
+ expect(obj1).not.toStrictEqual(expected)
38
+ expect(obj2).not.toStrictEqual(expected)
39
+ expect(obj3).not.toStrictEqual(expected)
40
+ })
41
+
42
+ it('should do a deep merge', () => {
43
+ const obj1 = { a: { b: 1, c: 1, d: { e: 1, f: 1 } } }
44
+ const obj2 = { a: { b: 2, d: { f: 'f' } } }
45
+
46
+ expect(mergeDeep(obj1, obj2)).toStrictEqual({
47
+ a: { b: 2, c: 1, d: { e: 1, f: 'f' } }
48
+ })
49
+ })
50
+
51
+ it('should not merge strings', () => {
52
+ const obj1 = { a: 'foo' }
53
+ const obj2 = { a: { b: 2, d: { f: 'f' } } }
54
+ const obj3 = { a: 'bar' }
55
+
56
+ const result = mergeDeep(obj1, obj2, obj3)
57
+
58
+ expect(result.a).toEqual('bar')
59
+ })
60
+
61
+ it('should clone objects during merge', () => {
62
+ const obj1 = { a: { b: 1 } }
63
+ const obj2 = { a: { c: 2 } }
64
+
65
+ const result = mergeDeep({}, obj1, obj2)
66
+
67
+ expect(result).toStrictEqual({ a: { b: 1, c: 2 } })
68
+ expect(result.a).not.toStrictEqual(obj1.a)
69
+ expect(result.a).not.toStrictEqual(obj2.a)
70
+ })
71
+
72
+ it('should not merge an object into an array', () => {
73
+ const obj1 = { a: { b: 1 } }
74
+ const obj2 = { a: ['foo', 'bar'] }
75
+
76
+ const result = mergeDeep({}, obj1, obj2)
77
+
78
+ expect(result).toStrictEqual({ a: ['foo', 'bar'] })
79
+ })
80
+
81
+ it('should deep clone arrays during merge', () => {
82
+ const obj1 = { a: [1, 2, [3, 4]] }
83
+ const obj2 = { b: [5, 6] }
84
+
85
+ const result = mergeDeep(obj1, obj2)
86
+
87
+ expect(result.a).toStrictEqual([1, 2, [3, 4]])
88
+ expect(result.a[2]).toStrictEqual([3, 4])
89
+ expect(result.b).toStrictEqual(obj2.b)
90
+ })
91
+
92
+ it('should union when both values are array', () => {
93
+ const obj1 = { a: [1, 2, [3, 4]] }
94
+ const obj2 = { a: [5, 6] }
95
+
96
+ const result = mergeDeep(obj1, obj2)
97
+
98
+ expect(result.a).toStrictEqual([1, 2, [3, 4], 5, 6])
99
+ expect(result.a[2]).toStrictEqual([3, 4])
100
+ })
101
+
102
+ it('should union when the first value is an array', () => {
103
+ const obj1 = { a: [1, 2, [3, 4]] }
104
+ const obj2 = { a: 5 }
105
+ const obj3 = { a: 6 }
106
+
107
+ const result = mergeDeep(obj1, obj2, obj3)
108
+
109
+ expect(result.a).toStrictEqual([1, 2, [3, 4], 5, 6])
110
+ expect(result.a[2]).toStrictEqual([3, 4])
111
+ })
112
+
113
+ it('should uniquify array values', () => {
114
+ const obj1 = { a: ['foo'] }
115
+ const obj2 = { a: ['bar'] }
116
+ const obj3 = { a: 'foo' }
117
+
118
+ const result = mergeDeep(obj1, obj2, obj3)
119
+
120
+ expect(result.a).toStrictEqual(['foo', 'bar'])
121
+ })
122
+
123
+ it('should copy source properties', () => {
124
+ expect(mergeDeep({ test: true }).test).toBe(true)
125
+ })
126
+
127
+ it('should not clone objects created with custom constructor', () => {
128
+ function TestType() {}
129
+ // @ts-expect-error intentional "new"
130
+ const func = new TestType()
131
+ expect(mergeDeep(func)).toEqual(func)
132
+ })
133
+ })
@@ -0,0 +1,44 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import '@testing-library/jest-dom'
26
+ import { ms } from '../ms'
27
+
28
+ describe('ms', () => {
29
+ it('handles ms unit', () => {
30
+ expect(ms('4ms')).toEqual(4)
31
+ })
32
+
33
+ it('converts s to ms', () => {
34
+ expect(ms('0.3s')).toEqual(0.3 * 1000)
35
+ })
36
+
37
+ it('handles unitless input', () => {
38
+ expect(ms('15')).toEqual(15)
39
+ })
40
+
41
+ it('handles numeric input', () => {
42
+ expect(ms(15)).toEqual(15)
43
+ })
44
+ })