-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathutils.test.js
More file actions
98 lines (86 loc) · 2.79 KB
/
utils.test.js
File metadata and controls
98 lines (86 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict'
const { describe, it } = require('node:test')
const assert = require('node:assert/strict')
const { setRaw, combineDeepmerge } = require('./utils')
const { StringSchema } = require('./StringSchema')
const { ObjectSchema } = require('./ObjectSchema')
describe('setRaw', () => {
it('add an attribute to a prop using ObjectSchema', () => {
const factory = ObjectSchema
const schema = setRaw(
{ schema: { properties: [{ name: 'foo', type: 'string' }] }, factory },
{ nullable: true }
)
assert.deepStrictEqual(schema.valueOf(), {
properties: {
foo: {
nullable: true,
type: 'string'
}
}
})
})
it('add an attribute to a prop using StringSchema', () => {
const factory = StringSchema
const schema = setRaw(
{ schema: { type: 'string', properties: [] }, factory },
{ nullable: true }
)
assert.deepStrictEqual(schema.valueOf(), {
nullable: true,
type: 'string'
})
})
})
describe('combineDeepmerge', () => {
it('should merge empty arrays', () => {
const result = combineDeepmerge([], [])
assert.deepStrictEqual(result, [])
})
it('should merge array with primitive values', () => {
const result = combineDeepmerge([1], [2])
assert.deepStrictEqual(result, [1, 2])
})
it('should merge arrays with primitive values', () => {
const result = combineDeepmerge([], [1, 2])
assert.deepStrictEqual(result, [1, 2])
})
it('should merge arrays with primitive values', () => {
const result = combineDeepmerge([1, 2], [1, 2, 3])
assert.deepStrictEqual(result, [1, 2, 3])
})
it('should merge array with simple Schemas', () => {
const result = combineDeepmerge([{ type: 'string' }], [{ type: 'string' }])
assert.deepStrictEqual(result, [{ type: 'string' }])
})
it('should merge array with named Schemas', () => {
const result = combineDeepmerge(
[{ name: 'variant 1', type: 'string' }],
[{ name: 'variant 2', type: 'string' }]
)
assert.deepStrictEqual(result, [
{ name: 'variant 1', type: 'string' },
{ name: 'variant 2', type: 'string' }
])
})
it('should merge array with same named Schemas', () => {
const result = combineDeepmerge(
[{ name: 'variant 2', type: 'string' }],
[{ name: 'variant 2', type: 'number' }]
)
assert.deepStrictEqual(result, [{ name: 'variant 2', type: 'number' }])
})
it('should merge array with same named Schemas', () => {
const result = combineDeepmerge(
[{ name: 'variant 2', type: 'string' }],
[
{ name: 'variant 2', type: 'number' },
{ name: 'variant 1', type: 'string' }
]
)
assert.deepStrictEqual(result, [
{ name: 'variant 2', type: 'number' },
{ name: 'variant 1', type: 'string' }
])
})
})