@domql/element 3.1.2 → 3.2.3
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.
- package/README.md +4 -6
- package/__tests__/checkIfOnUpdate.test.js +12 -12
- package/__tests__/children.test.js +34 -38
- package/__tests__/inheritStateUpdates.test.js +12 -12
- package/__tests__/renderElement.test.js +11 -11
- package/__tests__/resetElement.test.js +6 -6
- package/__tests__/set.test.js +32 -36
- package/__tests__/throughExecProps.test.js +12 -12
- package/__tests__/throughInitialDefine.test.js +16 -16
- package/__tests__/throughInitialExec.test.js +16 -16
- package/__tests__/throughUpdatedDefine.test.js +14 -14
- package/__tests__/throughUpdatedExec.test.js +17 -16
- package/__tests__/update.test.js +54 -54
- package/children.js +5 -6
- package/create.js +18 -20
- package/dist/cjs/children.js +4 -2
- package/dist/cjs/create.js +16 -16
- package/dist/cjs/extend.js +88 -0
- package/dist/cjs/iterate.js +76 -20
- package/dist/cjs/mixins/content.js +73 -0
- package/dist/cjs/mixins/html.js +1 -1
- package/dist/cjs/mixins/registry.js +2 -2
- package/dist/cjs/mixins/scope.js +1 -1
- package/dist/cjs/mixins/state.js +2 -2
- package/dist/cjs/mixins/text.js +4 -4
- package/dist/cjs/node.js +15 -15
- package/dist/cjs/set.js +22 -27
- package/dist/cjs/update.js +24 -33
- package/dist/cjs/utils/applyParam.js +4 -4
- package/dist/cjs/utils/extendUtils.js +132 -0
- package/dist/cjs/utils/propEvents.js +39 -0
- package/dist/esm/children.js +5 -3
- package/dist/esm/create.js +16 -16
- package/dist/esm/extend.js +74 -0
- package/dist/esm/iterate.js +77 -22
- package/dist/esm/mixins/content.js +53 -0
- package/dist/esm/mixins/html.js +1 -1
- package/dist/esm/mixins/registry.js +1 -1
- package/dist/esm/mixins/scope.js +1 -1
- package/dist/esm/mixins/state.js +3 -3
- package/dist/esm/mixins/text.js +4 -4
- package/dist/esm/node.js +15 -15
- package/dist/esm/set.js +23 -28
- package/dist/esm/update.js +24 -33
- package/dist/esm/utils/applyParam.js +5 -5
- package/dist/esm/utils/extendUtils.js +119 -0
- package/dist/esm/utils/propEvents.js +19 -0
- package/extend.js +98 -0
- package/iterate.js +80 -25
- package/mixins/content.js +65 -0
- package/mixins/html.js +1 -1
- package/mixins/registry.js +1 -1
- package/mixins/scope.js +1 -1
- package/mixins/state.js +3 -3
- package/mixins/text.js +4 -4
- package/node.js +15 -15
- package/package.json +8 -8
- package/set.js +23 -28
- package/update.js +25 -34
- package/utils/applyParam.js +5 -5
- package/utils/extendUtils.js +149 -0
- package/utils/propEvents.js +19 -0
- package/dist/cjs/__tests__/checkIfOnUpdate.test.js +0 -73
- package/dist/cjs/__tests__/children.test.js +0 -177
- package/dist/cjs/__tests__/define.test.js +0 -75
- package/dist/cjs/__tests__/inheritStateUpdates.test.js +0 -62
- package/dist/cjs/__tests__/renderElement.test.js +0 -138
- package/dist/cjs/__tests__/resetElement.test.js +0 -35
- package/dist/cjs/__tests__/set.test.js +0 -256
- package/dist/cjs/__tests__/throughExecProps.test.js +0 -62
- package/dist/cjs/__tests__/throughInitialDefine.test.js +0 -79
- package/dist/cjs/__tests__/throughInitialExec.test.js +0 -73
- package/dist/cjs/__tests__/throughUpdatedDefine.test.js +0 -69
- package/dist/cjs/__tests__/throughUpdatedExec.test.js +0 -84
- package/dist/cjs/__tests__/tree.test.js +0 -11
- package/dist/cjs/__tests__/update.test.js +0 -222
- package/dist/esm/__tests__/checkIfOnUpdate.test.js +0 -73
- package/dist/esm/__tests__/children.test.js +0 -177
- package/dist/esm/__tests__/define.test.js +0 -53
- package/dist/esm/__tests__/inheritStateUpdates.test.js +0 -62
- package/dist/esm/__tests__/renderElement.test.js +0 -116
- package/dist/esm/__tests__/resetElement.test.js +0 -35
- package/dist/esm/__tests__/set.test.js +0 -256
- package/dist/esm/__tests__/throughExecProps.test.js +0 -62
- package/dist/esm/__tests__/throughInitialDefine.test.js +0 -79
- package/dist/esm/__tests__/throughInitialExec.test.js +0 -73
- package/dist/esm/__tests__/throughUpdatedDefine.test.js +0 -69
- package/dist/esm/__tests__/throughUpdatedExec.test.js +0 -84
- package/dist/esm/__tests__/tree.test.js +0 -11
- package/dist/esm/__tests__/update.test.js +0 -222
package/README.md
CHANGED
|
@@ -9,12 +9,10 @@ import DOM from 'domql'
|
|
|
9
9
|
|
|
10
10
|
const Poster = {
|
|
11
11
|
extends: [Link, Img],
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
background: '#fff'
|
|
17
|
-
}
|
|
12
|
+
boxSize: [100, 200],
|
|
13
|
+
borderRadius: 12,
|
|
14
|
+
padding: 16,
|
|
15
|
+
background: '#fff'
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
DOM.create(Poster, document.body)
|
|
@@ -44,60 +44,60 @@ describe('checkIfOnUpdate via update()', () => {
|
|
|
44
44
|
options = {}
|
|
45
45
|
})
|
|
46
46
|
|
|
47
|
-
it('uses props.if when element.if missing',
|
|
47
|
+
it('uses props.if when element.if missing', () => {
|
|
48
48
|
delete element.if
|
|
49
49
|
element.props.if = () => false
|
|
50
|
-
|
|
50
|
+
update.call(element, {}, options)
|
|
51
51
|
expect(element.node).toEqual(document.createElement('div'))
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
-
it('retains state when __hasRootState=true',
|
|
54
|
+
it('retains state when __hasRootState=true', () => {
|
|
55
55
|
element.__ref.__hasRootState = true
|
|
56
56
|
element.state.critical = true
|
|
57
57
|
element.__ref.__if = false
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
update.call(element, {}, options)
|
|
60
60
|
|
|
61
61
|
expect(element.state.critical).toBe(true)
|
|
62
62
|
expect(element.state.preserved).toBeUndefined()
|
|
63
63
|
})
|
|
64
64
|
|
|
65
|
-
it('processes nested content with parseDeep',
|
|
65
|
+
it('processes nested content with parseDeep', () => {
|
|
66
66
|
element.content = {
|
|
67
67
|
parseDeep: () => ({ parsed: true }),
|
|
68
68
|
existing: 'data'
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
update.call(element, {}, options)
|
|
72
72
|
|
|
73
73
|
expect(element.content.parsed).toBe(true)
|
|
74
74
|
expect(element.content.existing).toBeUndefined()
|
|
75
75
|
})
|
|
76
76
|
|
|
77
|
-
it('reattaches after previous sibling',
|
|
77
|
+
it('reattaches after previous sibling', () => {
|
|
78
78
|
const prevNode = document.createElement('span')
|
|
79
79
|
parent.node.appendChild(prevNode)
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
update.call(element, {}, options)
|
|
82
82
|
|
|
83
83
|
const newElement = parent.node.children[0]
|
|
84
84
|
expect(newElement).toEqual(document.createElement('span'))
|
|
85
85
|
expect(newElement.previousSibling).toBe(null)
|
|
86
86
|
})
|
|
87
87
|
|
|
88
|
-
// it('reattaches before next sibling',
|
|
88
|
+
// it('reattaches before next sibling', () => {
|
|
89
89
|
// const nextNode = document.createElement('p')
|
|
90
90
|
// parent.node.appendChild(nextNode)
|
|
91
91
|
|
|
92
|
-
//
|
|
92
|
+
// update.call(element, {}, options)
|
|
93
93
|
|
|
94
94
|
// const newElement = parent.node.children[0]
|
|
95
95
|
// expect(newElement).toEqual(document.createElement('p'))
|
|
96
96
|
// expect(newElement.nextSibling).toBe(null)
|
|
97
97
|
// })
|
|
98
98
|
|
|
99
|
-
// it('appends to parent when no siblings exist',
|
|
100
|
-
//
|
|
99
|
+
// it('appends to parent when no siblings exist', () => {
|
|
100
|
+
// update.call(element, {}, options)
|
|
101
101
|
// expect(parent.node.children).toHaveLength(0)
|
|
102
102
|
// })
|
|
103
103
|
})
|
|
@@ -16,23 +16,23 @@ describe('children', () => {
|
|
|
16
16
|
node = {}
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
-
it('handles null/undefined params',
|
|
20
|
-
const result =
|
|
19
|
+
it('handles null/undefined params', () => {
|
|
20
|
+
const result = setChildren(null, element, node)
|
|
21
21
|
expect(result).toBeUndefined()
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
it('handles direct string children',
|
|
25
|
-
const result =
|
|
24
|
+
it('handles direct string children', () => {
|
|
25
|
+
const result = setChildren('Hello World', element, node)
|
|
26
26
|
expect(result).toEqual({ tag: 'fragment', 0: { text: 'Hello World' } })
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
-
it('handles numeric children',
|
|
30
|
-
const result =
|
|
29
|
+
it('handles numeric children', () => {
|
|
30
|
+
const result = setChildren(42, element, node)
|
|
31
31
|
expect(result).toEqual({ tag: 'fragment', 0: { text: 42 } })
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
it('handles array of primitive values with childrenAs prop',
|
|
35
|
-
const result =
|
|
34
|
+
it('handles array of primitive values with childrenAs prop', () => {
|
|
35
|
+
const result = setChildren(['one', 'two'], element, node)
|
|
36
36
|
|
|
37
37
|
expect(result).toEqual({
|
|
38
38
|
tag: 'fragment',
|
|
@@ -41,9 +41,9 @@ describe('children', () => {
|
|
|
41
41
|
})
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
it('handles array of primitive values with childrenAs state',
|
|
44
|
+
it('handles array of primitive values with childrenAs state', () => {
|
|
45
45
|
element.props.childrenAs = 'state'
|
|
46
|
-
const result =
|
|
46
|
+
const result = setChildren(['one', 'two'], element, node)
|
|
47
47
|
|
|
48
48
|
expect(result).toEqual({
|
|
49
49
|
tag: 'fragment',
|
|
@@ -52,34 +52,34 @@ describe('children', () => {
|
|
|
52
52
|
})
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
-
it('caches children and detects changes',
|
|
55
|
+
it('caches children and detects changes', () => {
|
|
56
56
|
const children1 = [{ id: 1 }, { id: 2 }]
|
|
57
57
|
const children2 = [{ id: 1 }, { id: 2 }]
|
|
58
58
|
const children3 = [{ id: 1 }, { id: 3 }]
|
|
59
59
|
|
|
60
60
|
// First call
|
|
61
|
-
|
|
61
|
+
setChildren(children1, element, node)
|
|
62
62
|
expect(element.__ref.__childrenCache).toEqual(children1)
|
|
63
63
|
expect(element.__ref.__noChildrenDifference).toBeUndefined()
|
|
64
64
|
|
|
65
65
|
// Same content, different reference
|
|
66
|
-
|
|
66
|
+
setChildren(children2, element, node)
|
|
67
67
|
expect(element.__ref.__noChildrenDifference).toBe(true)
|
|
68
68
|
|
|
69
69
|
// Different content
|
|
70
|
-
|
|
70
|
+
setChildren(children3, element, node)
|
|
71
71
|
expect(element.__ref.__noChildrenDifference).toBeUndefined()
|
|
72
72
|
expect(element.__ref.__childrenCache).toEqual(children3)
|
|
73
73
|
})
|
|
74
74
|
|
|
75
|
-
it('handles mixed React and normal components',
|
|
75
|
+
it('handles mixed React and normal components', () => {
|
|
76
76
|
const mixedChildren = [
|
|
77
77
|
{ type: 'div', text: 'Normal' },
|
|
78
78
|
{ $$typeof: Symbol('react') },
|
|
79
79
|
{ type: 'span', text: 'Another' }
|
|
80
80
|
]
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
setChildren(mixedChildren, element, node)
|
|
83
83
|
|
|
84
84
|
expect(element.call).toHaveBeenCalledWith(
|
|
85
85
|
'renderReact',
|
|
@@ -88,13 +88,13 @@ describe('children', () => {
|
|
|
88
88
|
)
|
|
89
89
|
})
|
|
90
90
|
|
|
91
|
-
it('handles state-based children',
|
|
91
|
+
it('handles state-based children', () => {
|
|
92
92
|
element.state = {
|
|
93
93
|
items: ['a', 'b'],
|
|
94
94
|
parse: () => ['parsed a', 'parsed b']
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
const result =
|
|
97
|
+
const result = setChildren('state', element, node)
|
|
98
98
|
expect(result).toEqual({
|
|
99
99
|
tag: 'fragment',
|
|
100
100
|
0: { text: 'parsed a' },
|
|
@@ -102,9 +102,9 @@ describe('children', () => {
|
|
|
102
102
|
})
|
|
103
103
|
})
|
|
104
104
|
|
|
105
|
-
it('handles async function parameters',
|
|
106
|
-
const asyncParam =
|
|
107
|
-
const result =
|
|
105
|
+
it('handles async function parameters', () => {
|
|
106
|
+
const asyncParam = () => ['async1', 'async2']
|
|
107
|
+
const result = setChildren(asyncParam, element, node)
|
|
108
108
|
|
|
109
109
|
expect(result).toEqual({
|
|
110
110
|
tag: 'fragment',
|
|
@@ -113,7 +113,7 @@ describe('children', () => {
|
|
|
113
113
|
})
|
|
114
114
|
})
|
|
115
115
|
|
|
116
|
-
it('handles nested object structures',
|
|
116
|
+
it('handles nested object structures', () => {
|
|
117
117
|
const nestedChildren = {
|
|
118
118
|
header: { text: 'Title' },
|
|
119
119
|
content: {
|
|
@@ -121,7 +121,7 @@ describe('children', () => {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
const result =
|
|
124
|
+
const result = setChildren(nestedChildren, element, node)
|
|
125
125
|
expect(result).toEqual({
|
|
126
126
|
tag: 'fragment',
|
|
127
127
|
0: { text: 'Title' },
|
|
@@ -129,24 +129,20 @@ describe('children', () => {
|
|
|
129
129
|
})
|
|
130
130
|
})
|
|
131
131
|
|
|
132
|
-
it('handles empty arrays and objects',
|
|
133
|
-
let result =
|
|
132
|
+
it('handles empty arrays and objects', () => {
|
|
133
|
+
let result = setChildren([], element, node)
|
|
134
134
|
expect(result).toEqual({
|
|
135
135
|
tag: 'fragment'
|
|
136
136
|
})
|
|
137
137
|
|
|
138
|
-
result =
|
|
138
|
+
result = setChildren({}, element, node)
|
|
139
139
|
expect(result).toEqual({
|
|
140
140
|
tag: 'fragment'
|
|
141
141
|
})
|
|
142
142
|
})
|
|
143
143
|
|
|
144
|
-
it('handles falsy values in arrays',
|
|
145
|
-
const result =
|
|
146
|
-
[null, undefined, false, 0, ''],
|
|
147
|
-
element,
|
|
148
|
-
node
|
|
149
|
-
)
|
|
144
|
+
it('handles falsy values in arrays', () => {
|
|
145
|
+
const result = setChildren([null, undefined, false, 0, ''], element, node)
|
|
150
146
|
expect(result).toEqual({
|
|
151
147
|
tag: 'fragment',
|
|
152
148
|
3: { text: 0 },
|
|
@@ -154,7 +150,7 @@ describe('children', () => {
|
|
|
154
150
|
})
|
|
155
151
|
})
|
|
156
152
|
|
|
157
|
-
it('handles React components with falsy values in array',
|
|
153
|
+
it('handles React components with falsy values in array', () => {
|
|
158
154
|
const mixedChildren = [
|
|
159
155
|
null,
|
|
160
156
|
{ $$typeof: Symbol('react') },
|
|
@@ -163,7 +159,7 @@ describe('children', () => {
|
|
|
163
159
|
false
|
|
164
160
|
]
|
|
165
161
|
|
|
166
|
-
|
|
162
|
+
setChildren(mixedChildren, element, node)
|
|
167
163
|
|
|
168
164
|
expect(element.call).toHaveBeenCalledWith(
|
|
169
165
|
'renderReact',
|
|
@@ -172,7 +168,7 @@ describe('children', () => {
|
|
|
172
168
|
)
|
|
173
169
|
})
|
|
174
170
|
|
|
175
|
-
it('handles nested state parsing',
|
|
171
|
+
it('handles nested state parsing', () => {
|
|
176
172
|
element.state = {
|
|
177
173
|
nested: {
|
|
178
174
|
items: ['c', 'd']
|
|
@@ -180,20 +176,20 @@ describe('children', () => {
|
|
|
180
176
|
}
|
|
181
177
|
element.state.nested.__proto__.parse = () => ['parsed c', 'parsed d']
|
|
182
178
|
|
|
183
|
-
const result =
|
|
179
|
+
const result = setChildren('nested', element, node)
|
|
184
180
|
expect(result).toEqual({
|
|
185
181
|
tag: 'fragment',
|
|
186
182
|
0: { state: ['c', 'd'] }
|
|
187
183
|
})
|
|
188
184
|
})
|
|
189
185
|
|
|
190
|
-
it('handles mixed state and regular objects',
|
|
186
|
+
it('handles mixed state and regular objects', () => {
|
|
191
187
|
element.state = {
|
|
192
188
|
header: { parse: () => 'Header' },
|
|
193
189
|
footer: { parse: () => 'Footer' }
|
|
194
190
|
}
|
|
195
191
|
|
|
196
|
-
const result =
|
|
192
|
+
const result = setChildren(
|
|
197
193
|
{
|
|
198
194
|
header: 'header',
|
|
199
195
|
content: { text: 'Content' },
|
|
@@ -28,52 +28,52 @@ describe('update() with inheritStateUpdates', () => {
|
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
// Test 1: Continue update when state inheritance succeeds
|
|
31
|
-
it('processes full update flow when state is inherited',
|
|
32
|
-
|
|
31
|
+
it('processes full update flow when state is inherited', () => {
|
|
32
|
+
update.call(element, { props: { newProp: true } }, options)
|
|
33
33
|
expect(element.props.newProp).toBe(true)
|
|
34
34
|
expect(element.state.baseState).toBe(true) // Inherited from parent
|
|
35
35
|
})
|
|
36
36
|
|
|
37
37
|
// Test 2: Preserve existing state when inheritance blocked
|
|
38
|
-
it('maintains state when preventInheritedStateUpdate=true',
|
|
38
|
+
it('maintains state when preventInheritedStateUpdate=true', () => {
|
|
39
39
|
options.preventInheritedStateUpdate = true
|
|
40
40
|
element.state = { existing: 'state' }
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
update.call(element, {}, options)
|
|
43
43
|
expect(element.state).toEqual({ baseState: true })
|
|
44
44
|
})
|
|
45
45
|
|
|
46
46
|
// Test 3: Execute state functions when forced
|
|
47
|
-
it('overwrites state with function result',
|
|
47
|
+
it('overwrites state with function result', () => {
|
|
48
48
|
element.__ref.__state = () => ({ calculated: 42 })
|
|
49
49
|
options.execStateFunction = true
|
|
50
50
|
options.stateFunctionOverwrite = true
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
update.call(element, {}, options)
|
|
53
53
|
expect(element.state.calculated).toEqual(42)
|
|
54
54
|
})
|
|
55
55
|
|
|
56
56
|
// Test 4: Block updates via beforeStateUpdate event
|
|
57
|
-
it('preserves state when beforeStateUpdate rejects',
|
|
57
|
+
it('preserves state when beforeStateUpdate rejects', () => {
|
|
58
58
|
element.onBeforeStateUpdate = () => false
|
|
59
|
-
|
|
59
|
+
update.call(element, { props: { shouldChange: true } }, options)
|
|
60
60
|
expect(element.state).toEqual({ baseState: true })
|
|
61
61
|
expect(element.props.shouldChange).toBe(true)
|
|
62
62
|
})
|
|
63
63
|
|
|
64
64
|
// Test 5: Handle parent state changes
|
|
65
|
-
it('reflects parent state updates',
|
|
65
|
+
it('reflects parent state updates', () => {
|
|
66
66
|
element.parent.state = { updatedParentState: true }
|
|
67
|
-
|
|
67
|
+
update.call(element, {}, options)
|
|
68
68
|
expect(element.state.updatedParentState).toBe(true)
|
|
69
69
|
})
|
|
70
70
|
|
|
71
71
|
// Test 6: Maintain local state when root state exists
|
|
72
|
-
it('preserves local state when __hasRootState=true',
|
|
72
|
+
it('preserves local state when __hasRootState=true', () => {
|
|
73
73
|
element.__ref.__hasRootState = true
|
|
74
74
|
element.state = { local: 'data' }
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
update.call(element, {}, options)
|
|
77
77
|
expect(element.state.local).toBe('data')
|
|
78
78
|
})
|
|
79
79
|
})
|
|
@@ -33,7 +33,7 @@ describe('create()', () => {
|
|
|
33
33
|
props.__ref.__skipCreate = true
|
|
34
34
|
props.scope = undefined
|
|
35
35
|
const { create } = await import('../create')
|
|
36
|
-
|
|
36
|
+
create(props, parent, 'passedKey', {
|
|
37
37
|
onlyResolveExtends: true,
|
|
38
38
|
define: ['test']
|
|
39
39
|
})
|
|
@@ -45,7 +45,7 @@ describe('create()', () => {
|
|
|
45
45
|
props.__ref.__if = true
|
|
46
46
|
props.scope = 'state'
|
|
47
47
|
const { create } = await import('../create')
|
|
48
|
-
|
|
48
|
+
create(props, parent, 'passedKey', {
|
|
49
49
|
onlyResolveExtends: true,
|
|
50
50
|
define: ['test']
|
|
51
51
|
})
|
|
@@ -57,7 +57,7 @@ describe('create()', () => {
|
|
|
57
57
|
process.env.NODE_ENV = 'prod'
|
|
58
58
|
props.__ref = undefined
|
|
59
59
|
const { create } = await import('../create')
|
|
60
|
-
|
|
60
|
+
create(props, parent, 'passedKey', { onlyResolveExtends: true })
|
|
61
61
|
expect(parent.__ref).toBeUndefined()
|
|
62
62
|
expect(parent.passedKey).toBe(props.__ref.parent.passedKey)
|
|
63
63
|
})
|
|
@@ -66,7 +66,7 @@ describe('create()', () => {
|
|
|
66
66
|
process.env.NODE_ENV = 'prod'
|
|
67
67
|
props.__ref = undefined
|
|
68
68
|
const { create } = await import('../create')
|
|
69
|
-
|
|
69
|
+
create(props, parent, 'passedKey')
|
|
70
70
|
expect(parent.__ref).toBeUndefined()
|
|
71
71
|
expect(parent.passedKey).toBe(props.__ref.parent.passedKey)
|
|
72
72
|
})
|
|
@@ -74,7 +74,7 @@ describe('create()', () => {
|
|
|
74
74
|
test('should attaches element to parent when ref.__if is false', async () => {
|
|
75
75
|
process.env.NODE_ENV = 'prod'
|
|
76
76
|
const { create } = await import('../create')
|
|
77
|
-
|
|
77
|
+
create(props, parent, 'passedKey')
|
|
78
78
|
expect(parent.__ref).toBeUndefined()
|
|
79
79
|
expect(parent.passedKey).toBe(props.__ref.parent.passedKey)
|
|
80
80
|
})
|
|
@@ -83,7 +83,7 @@ describe('create()', () => {
|
|
|
83
83
|
process.env.NODE_ENV = 'prod'
|
|
84
84
|
props.__if = true
|
|
85
85
|
const { create } = await import('../create')
|
|
86
|
-
|
|
86
|
+
create(props, parent, 'passedKey')
|
|
87
87
|
expect(parent.testKey).toBe('parentTestKey')
|
|
88
88
|
expect(parent.passedKey).toBe(props.__ref.parent.passedKey)
|
|
89
89
|
})
|
|
@@ -92,7 +92,7 @@ describe('create()', () => {
|
|
|
92
92
|
process.env.NODE_ENV = 'prod'
|
|
93
93
|
props.__ref = { __uniqId: 'existing-id', path: [] }
|
|
94
94
|
const { create } = await import('../create')
|
|
95
|
-
|
|
95
|
+
create(props, {}, 'passedKey')
|
|
96
96
|
expect(props.__ref.__uniqId).toBeDefined()
|
|
97
97
|
})
|
|
98
98
|
|
|
@@ -100,7 +100,7 @@ describe('create()', () => {
|
|
|
100
100
|
process.env.NODE_ENV = 'prod'
|
|
101
101
|
props.__ref = { path: ['loop-path'], __uniqId: undefined }
|
|
102
102
|
const { create } = await import('../create')
|
|
103
|
-
|
|
103
|
+
create(props, {}, 'passedKey')
|
|
104
104
|
expect(props.__ref.__uniqId).toBeDefined()
|
|
105
105
|
})
|
|
106
106
|
|
|
@@ -108,7 +108,7 @@ describe('create()', () => {
|
|
|
108
108
|
process.env.NODE_ENV = 'prod'
|
|
109
109
|
props.__ref = { path: ['ComponentsGrid', 'x', 'y', 'z'] }
|
|
110
110
|
const { create } = await import('../create')
|
|
111
|
-
|
|
111
|
+
create(props, {}, ['ComponentsGrid', 'x', 'y', 'z'])
|
|
112
112
|
expect(props.__ref.path).toEqual(['ComponentsGrid,x,y,z'])
|
|
113
113
|
})
|
|
114
114
|
|
|
@@ -116,7 +116,7 @@ describe('create()', () => {
|
|
|
116
116
|
process.env.NODE_ENV = 'prod'
|
|
117
117
|
props.__ref = { path: ['demoComponent', 'a', 'b', 'c'] }
|
|
118
118
|
const { create } = await import('../create')
|
|
119
|
-
|
|
119
|
+
create(props, {}, ['demoComponent', 'a', 'b', 'c'])
|
|
120
120
|
expect(props.__ref.path).toEqual(['demoComponent,a,b,c'])
|
|
121
121
|
})
|
|
122
122
|
|
|
@@ -125,7 +125,7 @@ describe('create()', () => {
|
|
|
125
125
|
props.__ref = { __if: false, path: [] }
|
|
126
126
|
props.key = 'fallbackKey'
|
|
127
127
|
const { create } = await import('../create')
|
|
128
|
-
|
|
128
|
+
create(props, parent, null)
|
|
129
129
|
expect(props.__ref.parent.fallbackKey).toBeDefined()
|
|
130
130
|
})
|
|
131
131
|
})
|
|
@@ -15,15 +15,15 @@ describe('resetContent', () => {
|
|
|
15
15
|
}
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
it('should update contentElementKey from options',
|
|
19
|
-
|
|
18
|
+
it('should update contentElementKey from options', () => {
|
|
19
|
+
resetContent({}, element, { contentElementKey: 'mainContent' })
|
|
20
20
|
|
|
21
21
|
expect(ref.contentElementKey).toBe('mainContent')
|
|
22
22
|
expect(element.mainContent).toBeDefined()
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
it('should merge options correctly',
|
|
26
|
-
|
|
25
|
+
it('should merge options correctly', () => {
|
|
26
|
+
resetContent({}, element, { customOption: true })
|
|
27
27
|
|
|
28
28
|
expect(element.content).toEqual(
|
|
29
29
|
expect.objectContaining({
|
|
@@ -33,10 +33,10 @@ describe('resetContent', () => {
|
|
|
33
33
|
)
|
|
34
34
|
})
|
|
35
35
|
|
|
36
|
-
it('should maintain context through reset',
|
|
36
|
+
it('should maintain context through reset', () => {
|
|
37
37
|
const originalContext = element.context
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
resetContent({}, element, {})
|
|
40
40
|
|
|
41
41
|
expect(element.context).toBe(originalContext)
|
|
42
42
|
expect(element.content.context).toBe(originalContext)
|