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