@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.
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
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [8.52.1-snapshot-6](https://github.com/instructure/instructure-ui/compare/v8.52.0...v8.52.1-snapshot-6) (2024-02-07)
6
+ ## [8.52.1-snapshot-11](https://github.com/instructure/instructure-ui/compare/v8.52.0...v8.52.1-snapshot-11) (2024-02-08)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-utils
9
9
 
@@ -0,0 +1,40 @@
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
+ import '@testing-library/jest-dom';
25
+ import { camelize } from '../camelize';
26
+ describe('convertCase', () => {
27
+ describe('camelize', () => {
28
+ it('handles hyphenated strings', () => {
29
+ expect(camelize('foo-bar')).toEqual('fooBar');
30
+ expect(camelize('baz-qux-foo')).toEqual('bazQuxFoo');
31
+ expect(camelize('xx-small')).toEqual('xxSmall');
32
+ expect(camelize('border-radius-x-large')).toEqual('borderRadiusXLarge');
33
+ expect(camelize('margin-xxLarge')).toEqual('marginXxLarge');
34
+ });
35
+ it('does not modify already camel cased strings', () => {
36
+ expect(camelize('fooBar')).toEqual('fooBar');
37
+ expect(camelize('bazQuxFoo')).toEqual('bazQuxFoo');
38
+ });
39
+ });
40
+ });
@@ -0,0 +1,52 @@
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
+ import '@testing-library/jest-dom';
25
+ import { cloneArray } from '../cloneArray';
26
+ import { deepEqual } from '../deepEqual';
27
+ describe('cloneArray', () => {
28
+ it('should return an array', () => {
29
+ const arr = [['one', 'two'], ['three']];
30
+ const newArr = cloneArray(arr);
31
+ expect(Array.isArray(newArr)).toBeTruthy();
32
+ });
33
+ it('should preserve sub arrays', () => {
34
+ const arr = [['one', 'two'], ['three'], [4, 5, 6], [7, [8, 9, 10], 11, 12]];
35
+ const newArr = cloneArray(arr);
36
+ expect(newArr.length).toEqual(4);
37
+ expect(newArr[0].length).toEqual(2);
38
+ expect(newArr[2][1]).toEqual(5);
39
+ expect(Array.isArray(newArr[3][1])).toEqual(true);
40
+ expect(newArr[3][1][2]).toEqual(10);
41
+ });
42
+ it('should return a new array', () => {
43
+ const arr = [['one', 'two'], ['three']];
44
+ const newArr = cloneArray(arr);
45
+ expect(deepEqual(arr, newArr)).toEqual(true);
46
+ newArr[0][1] = '2';
47
+ expect(deepEqual(arr, newArr)).toEqual(false);
48
+ const newArr2 = cloneArray(arr);
49
+ arr[0][0] = '1';
50
+ expect(deepEqual(arr, newArr2)).toEqual(false);
51
+ });
52
+ });
@@ -0,0 +1,50 @@
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 { createChainedFunction } from '../createChainedFunction';
27
+ describe('createChainedFunction', () => {
28
+ it('should return null if no function provided', () => {
29
+ expect(createChainedFunction(null, void 0)).toEqual(null);
30
+ });
31
+ it('should return a function', () => {
32
+ expect(typeof createChainedFunction(() => {})).toEqual('function');
33
+ });
34
+ it('should throw an error if something other than function, null, undefined provided', () => {
35
+ expect(() => {
36
+ // @ts-expect-error intentionally bad code
37
+ createChainedFunction(12345);
38
+ }).toThrow(Error);
39
+ });
40
+ it('should execute all the functions', () => {
41
+ const spies = Array.from({
42
+ length: 5
43
+ }, () => jest.fn());
44
+ const chain = createChainedFunction(...spies);
45
+ chain();
46
+ spies.forEach(spy => {
47
+ expect(spy).toHaveBeenCalledTimes(1);
48
+ });
49
+ });
50
+ });
@@ -0,0 +1,60 @@
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
+ import '@testing-library/jest-dom';
25
+ import { generateId } from '../generateId';
26
+ describe('generateId', () => {
27
+ it('should generate unique ids for the same instance', () => {
28
+ const seed = new Map();
29
+ const component = 'TestComponent';
30
+ const inst1 = generateId(component, seed);
31
+ const inst2 = generateId(component, seed);
32
+ expect(inst1).not.toEqual(inst2);
33
+ });
34
+ it('should create ids deterministicly', () => {
35
+ const seed1 = new Map();
36
+ const component = 'TestComponent';
37
+
38
+ // Simulate rendering component: TestComponent
39
+ const render1 = generateId(component, seed1);
40
+
41
+ // Suppose we have a refresh, meaning the instanceCounter will be reseted:
42
+ const seed2 = new Map();
43
+ const render2 = generateId(component, seed2);
44
+ expect(render1).toEqual(render2);
45
+ });
46
+ it('should not create the same id for the same instance.', () => {
47
+ const counter = new Map();
48
+ const seed = new Map();
49
+ const component = 'TestComponent';
50
+ for (let i = 0; i <= 20000; i++) {
51
+ const id = generateId(component, seed);
52
+ if (!counter.has(id)) {
53
+ counter.set(id, false);
54
+ } else {
55
+ counter.set(id, true);
56
+ }
57
+ expect(counter.get(id)).toBe(false);
58
+ }
59
+ });
60
+ });
@@ -0,0 +1,415 @@
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
+ describe('hash', () => {
28
+ it('should error if supplied value is undefined', () => {
29
+ let error = false;
30
+ try {
31
+ expect(hash(void 0)).toEqual('');
32
+ } catch (err) {
33
+ error = true;
34
+ }
35
+ expect(error).toBe(true);
36
+ });
37
+ it('should allow specifying a max length', () => {
38
+ const result = hash('some value', 4);
39
+ expect(result).toBeDefined();
40
+ expect(result).toHaveLength(4);
41
+ });
42
+ describe('strings', () => {
43
+ it('hashes two identical strings to the same value', () => {
44
+ const result1 = hash('Some string with3_ distinct$() !_)(* va1ues');
45
+ const result2 = hash('Some string with3_ distinct$() !_)(* va1ues');
46
+ expect(result1).toBeDefined();
47
+ expect(result2).toBeDefined();
48
+ expect(result1).toEqual(result2);
49
+ });
50
+ it('hashes different strings to different values', () => {
51
+ const result1 = hash('Some string with3_ distinct$() !_)(* va1ues');
52
+ const result2 = hash('Some string with3_ distinct$() !_)(* va1ues ');
53
+ expect(result1).toBeDefined();
54
+ expect(result2).toBeDefined();
55
+ expect(result1).not.toEqual(result2);
56
+ });
57
+ });
58
+ describe('numbers', () => {
59
+ it('hashes two identical numbers to the same value', () => {
60
+ const result1 = hash(532);
61
+ const result2 = hash(532);
62
+ expect(result1).toBeDefined();
63
+ expect(result2).toBeDefined();
64
+ expect(result1).toEqual(result2);
65
+ });
66
+ it('hashes two different numbers to different values', () => {
67
+ const result1 = hash(532);
68
+ const result2 = hash(5321);
69
+ expect(result1).toBeDefined();
70
+ expect(result2).toBeDefined();
71
+ expect(result1).not.toEqual(result2);
72
+ });
73
+ });
74
+ describe('booleans', () => {
75
+ it('hashes true to the same value', () => {
76
+ const result1 = hash(true);
77
+ const result2 = hash(true);
78
+ expect(result1).toBeDefined();
79
+ expect(result2).toBeDefined();
80
+ expect(result1).toEqual(result2);
81
+ });
82
+ it('hashes false to the same value', () => {
83
+ const result1 = hash(false);
84
+ const result2 = hash(false);
85
+ expect(result1).toBeDefined();
86
+ expect(result2).toBeDefined();
87
+ expect(result1).toEqual(result2);
88
+ });
89
+ it('hashes true and false to different values', () => {
90
+ const result1 = hash(true);
91
+ const result2 = hash(false);
92
+ expect(result1).toBeDefined();
93
+ expect(result2).toBeDefined();
94
+ expect(result1).not.toEqual(result2);
95
+ });
96
+ });
97
+ describe('functions', () => {
98
+ it('hashes two identical arrow function expressions to the same value', () => {
99
+ const result1 = hash(() => 'foo');
100
+ const result2 = hash(() => 'foo');
101
+ expect(result1).toBeDefined();
102
+ expect(result2).toBeDefined();
103
+ expect(result1).toEqual(result2);
104
+ });
105
+ it('hashes two different arrow function expressions to different values', () => {
106
+ const result1 = hash(() => 'foo');
107
+ const result2 = hash(() => 'bar');
108
+ expect(result1).toBeDefined();
109
+ expect(result2).toBeDefined();
110
+ expect(result1).not.toEqual(result2);
111
+ });
112
+ it('hashes two identical functions to the same value', () => {
113
+ const result1 = hash(function myFunc() {
114
+ const foo = 1;
115
+ const bar = 2;
116
+ return foo + bar;
117
+ });
118
+ const result2 = hash(function myFunc() {
119
+ const foo = 1;
120
+ const bar = 2;
121
+ return foo + bar;
122
+ });
123
+ expect(result1).toBeDefined();
124
+ expect(result2).toBeDefined();
125
+ expect(result1).toEqual(result2);
126
+ });
127
+ it('hashes two identical functions with different names to different values', () => {
128
+ const result1 = hash(function myFunc() {
129
+ const foo = 1;
130
+ const bar = 2;
131
+ return foo + bar;
132
+ });
133
+ const result2 = hash(function myFunc1() {
134
+ const foo = 1;
135
+ const bar = 2;
136
+ return foo + bar;
137
+ });
138
+ expect(result1).toBeDefined();
139
+ expect(result2).toBeDefined();
140
+ expect(result1).not.toEqual(result2);
141
+ });
142
+ it('hashes two identical functions with different bodies to different values', () => {
143
+ const result1 = hash(function myFunc() {
144
+ const foo = 1;
145
+ const bar = 2;
146
+ return foo + bar;
147
+ });
148
+ const result2 = hash(function myFunc() {
149
+ const foo = 1;
150
+ const baz = 2;
151
+ return foo + baz;
152
+ });
153
+ expect(result1).toBeDefined();
154
+ expect(result2).toBeDefined();
155
+ expect(result1).not.toEqual(result2);
156
+ });
157
+ });
158
+ describe('objects', () => {
159
+ it('hashes two identical simple objects to the same value', () => {
160
+ const result1 = hash({
161
+ foo: 'foo',
162
+ bar: 'bar',
163
+ baz: 'baz'
164
+ });
165
+ const result2 = hash({
166
+ foo: 'foo',
167
+ bar: 'bar',
168
+ baz: 'baz'
169
+ });
170
+ expect(result1).toBeDefined();
171
+ expect(result2).toBeDefined();
172
+ expect(result1).toEqual(result2);
173
+ });
174
+ it('hashes two identical simple objects with rearranged keys to the same value', () => {
175
+ const result1 = hash({
176
+ foo: 'foo',
177
+ bar: 'bar',
178
+ baz: 'baz'
179
+ });
180
+ const result2 = hash({
181
+ baz: 'baz',
182
+ foo: 'foo',
183
+ bar: 'bar'
184
+ });
185
+ expect(result1).toBeDefined();
186
+ expect(result2).toBeDefined();
187
+ expect(result1).toEqual(result2);
188
+ });
189
+ it('hashes two different simple objects to different values', () => {
190
+ const result1 = hash({
191
+ foo: 'foo',
192
+ bar: 'bar',
193
+ baz: 'baz'
194
+ });
195
+ const result2 = hash({
196
+ foo: 'foo',
197
+ bar: 'ba',
198
+ baz: 'baz'
199
+ });
200
+ expect(result1).toBeDefined();
201
+ expect(result2).toBeDefined();
202
+ expect(result1).not.toEqual(result2);
203
+ });
204
+ it('hashes two identical complex objects to the same value', () => {
205
+ const result1 = hash({
206
+ foo: 'foo',
207
+ bar: [{
208
+ qux: 'qux',
209
+ qang: 'qaz'
210
+ }, {
211
+ ['foo-bar']: true
212
+ }],
213
+ baz: () => {
214
+ const hello = 'hello';
215
+ const world = 'world';
216
+ return hello + world;
217
+ }
218
+ });
219
+ const result2 = hash({
220
+ foo: 'foo',
221
+ bar: [{
222
+ qux: 'qux',
223
+ qang: 'qaz'
224
+ }, {
225
+ ['foo-bar']: true
226
+ }],
227
+ baz: () => {
228
+ const hello = 'hello';
229
+ const world = 'world';
230
+ return hello + world;
231
+ }
232
+ });
233
+ expect(result1).toBeDefined();
234
+ expect(result2).toBeDefined();
235
+ expect(result1).toEqual(result2);
236
+ });
237
+ it('hashes two identical complex objects with rearranged keys to the same value', () => {
238
+ const result1 = hash({
239
+ foo: 'foo',
240
+ bar: [{
241
+ qux: 'qux',
242
+ qang: 'qaz'
243
+ }, {
244
+ ['foo-bar']: true
245
+ }],
246
+ baz: () => {
247
+ const hello = 'hello';
248
+ const world = 'world';
249
+ return hello + world;
250
+ }
251
+ });
252
+ const result2 = hash({
253
+ bar: [{
254
+ qux: 'qux',
255
+ qang: 'qaz'
256
+ }, {
257
+ ['foo-bar']: true
258
+ }],
259
+ foo: 'foo',
260
+ baz: () => {
261
+ const hello = 'hello';
262
+ const world = 'world';
263
+ return hello + world;
264
+ }
265
+ });
266
+ expect(result1).toBeDefined();
267
+ expect(result2).toBeDefined();
268
+ expect(result1).toEqual(result2);
269
+ });
270
+ it('hashes two different simple objects to different values', () => {
271
+ const result1 = hash({
272
+ foo: 'foo',
273
+ bar: 'bar',
274
+ baz: 'baz'
275
+ });
276
+ const result2 = hash({
277
+ foo: 'foo',
278
+ bar: 'ba',
279
+ baz: 'baz'
280
+ });
281
+ expect(result1).toBeDefined();
282
+ expect(result2).toBeDefined();
283
+ expect(result1).not.toEqual(result2);
284
+ });
285
+ it('hashes two different complex objects to the same value', () => {
286
+ const result1 = hash({
287
+ foo: 'foo',
288
+ bar: [{
289
+ qux: 'qux',
290
+ qang: 'qaz'
291
+ }, {
292
+ ['foobar']: true
293
+ }],
294
+ baz: () => {
295
+ const hello = 'hello';
296
+ const world = 'world';
297
+ return hello + world;
298
+ }
299
+ });
300
+ const result2 = hash({
301
+ foo: 'foo',
302
+ bar: [{
303
+ qux: 'qux',
304
+ qang: 'qaz'
305
+ }, {
306
+ ['foo-bar']: true
307
+ }],
308
+ baz: () => {
309
+ const hello = 'hello';
310
+ const world = 'world';
311
+ return hello + world;
312
+ }
313
+ });
314
+ expect(result1).toBeDefined();
315
+ expect(result2).toBeDefined();
316
+ expect(result1).not.toEqual(result2);
317
+ });
318
+ });
319
+ describe('classes', () => {
320
+ it('hashes two identical classes to the same value', () => {
321
+ const result1 = hash(class Something {
322
+ constructor(settings) {
323
+ this._settings = void 0;
324
+ this.doSomething = () => {
325
+ return 'doing something';
326
+ };
327
+ this._settings = settings;
328
+ }
329
+ get settings() {
330
+ return this._settings;
331
+ }
332
+ });
333
+ const result2 = hash(class Something {
334
+ constructor(settings) {
335
+ this._settings = void 0;
336
+ this.doSomething = () => {
337
+ return 'doing something';
338
+ };
339
+ this._settings = settings;
340
+ }
341
+ get settings() {
342
+ return this._settings;
343
+ }
344
+ });
345
+ expect(result1).toBeDefined();
346
+ expect(result2).toBeDefined();
347
+ expect(result1).toEqual(result2);
348
+ });
349
+ it('hashes two classes with different content to different values', () => {
350
+ const result1 = hash(class Something {
351
+ constructor(settings) {
352
+ this._settings = void 0;
353
+ this.doSomething = () => {
354
+ return 'doing something';
355
+ };
356
+ this._settings = settings;
357
+ }
358
+ get settings() {
359
+ return this._settings;
360
+ }
361
+ });
362
+ const result2 = hash(class Something {
363
+ constructor(settings) {
364
+ this._settings = void 0;
365
+ this.doSomething = () => {
366
+ return 'doing something else';
367
+ };
368
+ this._settings = settings;
369
+ }
370
+ get settings() {
371
+ return this._settings;
372
+ }
373
+ });
374
+ expect(result1).toBeDefined();
375
+ expect(result2).toBeDefined();
376
+ expect(result1).not.toEqual(result2);
377
+ });
378
+ it('hashes two classes with different names to different values', () => {
379
+ const result1 = hash(class Something {
380
+ constructor(settings) {
381
+ this._settings = void 0;
382
+ this.doSomething = () => {
383
+ return 'doing something';
384
+ };
385
+ this._settings = settings;
386
+ }
387
+ get settings() {
388
+ return this._settings;
389
+ }
390
+ });
391
+ const result2 = hash(class Somethin {
392
+ constructor(settings) {
393
+ this._settings = void 0;
394
+ this.doSomething = () => {
395
+ return 'doing something';
396
+ };
397
+ this._settings = settings;
398
+ }
399
+ get settings() {
400
+ return this._settings;
401
+ }
402
+ });
403
+ expect(result1).toBeDefined();
404
+ expect(result2).toBeDefined();
405
+ expect(result1).not.toEqual(result2);
406
+ });
407
+ it('hashes null to the same value', () => {
408
+ const result1 = hash(null);
409
+ const result2 = hash(null);
410
+ expect(result1).toBeDefined();
411
+ expect(result2).toBeDefined();
412
+ expect(result1).toEqual(result2);
413
+ });
414
+ });
415
+ });