@domql/element 3.2.3 → 3.2.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.
- package/children.js +40 -12
- package/create.js +40 -26
- package/define.js +1 -1
- package/dist/cjs/children.js +39 -11
- package/dist/cjs/create.js +41 -11
- package/dist/cjs/define.js +1 -1
- package/dist/cjs/event/animationFrame.js +96 -0
- package/dist/cjs/event/can.js +28 -0
- package/dist/cjs/event/index.js +20 -0
- package/dist/cjs/event/on.js +84 -0
- package/dist/cjs/event/store.js +27 -0
- package/dist/cjs/extend.js +6 -6
- package/dist/cjs/index.js +9 -6
- package/dist/cjs/iterate.js +13 -13
- package/dist/cjs/methods/set.js +5 -0
- package/dist/cjs/methods/v2.js +1 -1
- package/dist/cjs/mixins/attr.js +3 -2
- package/dist/cjs/mixins/classList.js +11 -1
- package/dist/cjs/mixins/content.js +1 -2
- package/dist/cjs/mixins/html.js +1 -2
- package/dist/cjs/mixins/state.js +2 -2
- package/dist/cjs/mixins/style.js +11 -2
- package/dist/cjs/mixins/text.js +5 -1
- package/dist/cjs/node.js +8 -5
- package/dist/cjs/render/append.js +72 -0
- package/dist/cjs/render/cache.js +80 -0
- package/dist/cjs/render/create.js +25 -0
- package/dist/cjs/render/index.js +20 -0
- package/dist/cjs/set.js +12 -14
- package/dist/cjs/update.js +80 -40
- package/dist/cjs/utils/applyParam.js +3 -3
- package/dist/cjs/utils/extendUtils.js +5 -5
- package/dist/cjs/utils/index.js +2 -0
- package/dist/cjs/utils/propEvents.js +21 -4
- package/dist/esm/children.js +39 -11
- package/dist/esm/create.js +42 -11
- package/dist/esm/define.js +1 -1
- package/dist/esm/event/animationFrame.js +76 -0
- package/dist/esm/event/can.js +8 -0
- package/dist/esm/event/index.js +3 -0
- package/dist/esm/event/on.js +64 -0
- package/dist/esm/event/store.js +7 -0
- package/dist/esm/extend.js +7 -7
- package/dist/esm/index.js +8 -6
- package/dist/esm/iterate.js +13 -13
- package/dist/esm/methods/set.js +10 -0
- package/dist/esm/methods/v2.js +1 -1
- package/dist/esm/mixins/attr.js +4 -3
- package/dist/esm/mixins/classList.js +11 -1
- package/dist/esm/mixins/content.js +1 -2
- package/dist/esm/mixins/html.js +1 -2
- package/dist/esm/mixins/state.js +2 -2
- package/dist/esm/mixins/style.js +12 -3
- package/dist/esm/mixins/text.js +6 -2
- package/dist/esm/node.js +8 -5
- package/dist/esm/render/append.js +52 -0
- package/dist/esm/render/cache.js +60 -0
- package/dist/esm/render/create.js +5 -0
- package/dist/esm/render/index.js +3 -0
- package/dist/esm/set.js +12 -14
- package/dist/esm/update.js +80 -42
- package/dist/esm/utils/applyParam.js +3 -3
- package/dist/esm/utils/extendUtils.js +5 -5
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/propEvents.js +21 -4
- package/dist/iife/index.js +4718 -0
- package/extend.js +7 -10
- package/index.js +9 -6
- package/iterate.js +20 -13
- package/node.js +10 -8
- package/package.json +42 -18
- package/set.js +6 -5
- package/update.js +90 -52
- package/__tests__/checkIfOnUpdate.test.js +0 -103
- package/__tests__/children.test.js +0 -209
- package/__tests__/define.test.js +0 -75
- package/__tests__/inheritStateUpdates.test.js +0 -79
- package/__tests__/renderElement.test.js +0 -131
- package/__tests__/resetElement.test.js +0 -44
- package/__tests__/set.test.js +0 -312
- package/__tests__/throughExecProps.test.js +0 -86
- package/__tests__/throughInitialDefine.test.js +0 -104
- package/__tests__/throughInitialExec.test.js +0 -92
- package/__tests__/throughUpdatedDefine.test.js +0 -92
- package/__tests__/throughUpdatedExec.test.js +0 -111
- package/__tests__/tree.test.js +0 -15
- package/__tests__/update.test.js +0 -256
- package/dist/cjs/package.json +0 -4
- package/methods/set.js +0 -63
- package/methods/v2.js +0 -83
- package/mixins/attr.js +0 -32
- package/mixins/classList.js +0 -54
- package/mixins/content.js +0 -65
- package/mixins/data.js +0 -26
- package/mixins/html.js +0 -21
- package/mixins/index.js +0 -23
- package/mixins/registry.js +0 -46
- package/mixins/scope.js +0 -23
- package/mixins/state.js +0 -19
- package/mixins/style.js +0 -16
- package/mixins/text.js +0 -26
- package/utils/applyParam.js +0 -34
- package/utils/extendUtils.js +0 -149
- package/utils/index.js +0 -3
- package/utils/propEvents.js +0 -19
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { jest } from '@jest/globals'
|
|
2
|
-
import { setChildren } from '../children'
|
|
3
|
-
|
|
4
|
-
describe('children', () => {
|
|
5
|
-
let element, node
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
element = {
|
|
9
|
-
__ref: {},
|
|
10
|
-
state: {},
|
|
11
|
-
props: {},
|
|
12
|
-
call: jest.fn(),
|
|
13
|
-
removeContent: jest.fn(),
|
|
14
|
-
content: null
|
|
15
|
-
}
|
|
16
|
-
node = {}
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('handles null/undefined params', () => {
|
|
20
|
-
const result = setChildren(null, element, node)
|
|
21
|
-
expect(result).toBeUndefined()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('handles direct string children', () => {
|
|
25
|
-
const result = setChildren('Hello World', element, node)
|
|
26
|
-
expect(result).toEqual({ tag: 'fragment', 0: { text: 'Hello World' } })
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('handles numeric children', () => {
|
|
30
|
-
const result = setChildren(42, element, node)
|
|
31
|
-
expect(result).toEqual({ tag: 'fragment', 0: { text: 42 } })
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('handles array of primitive values with childrenAs prop', () => {
|
|
35
|
-
const result = setChildren(['one', 'two'], element, node)
|
|
36
|
-
|
|
37
|
-
expect(result).toEqual({
|
|
38
|
-
tag: 'fragment',
|
|
39
|
-
0: { text: 'one' },
|
|
40
|
-
1: { text: 'two' }
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('handles array of primitive values with childrenAs state', () => {
|
|
45
|
-
element.props.childrenAs = 'state'
|
|
46
|
-
const result = setChildren(['one', 'two'], element, node)
|
|
47
|
-
|
|
48
|
-
expect(result).toEqual({
|
|
49
|
-
tag: 'fragment',
|
|
50
|
-
0: { state: { value: 'one' } },
|
|
51
|
-
1: { state: { value: 'two' } }
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('caches children and detects changes', () => {
|
|
56
|
-
const children1 = [{ id: 1 }, { id: 2 }]
|
|
57
|
-
const children2 = [{ id: 1 }, { id: 2 }]
|
|
58
|
-
const children3 = [{ id: 1 }, { id: 3 }]
|
|
59
|
-
|
|
60
|
-
// First call
|
|
61
|
-
setChildren(children1, element, node)
|
|
62
|
-
expect(element.__ref.__childrenCache).toEqual(children1)
|
|
63
|
-
expect(element.__ref.__noChildrenDifference).toBeUndefined()
|
|
64
|
-
|
|
65
|
-
// Same content, different reference
|
|
66
|
-
setChildren(children2, element, node)
|
|
67
|
-
expect(element.__ref.__noChildrenDifference).toBe(true)
|
|
68
|
-
|
|
69
|
-
// Different content
|
|
70
|
-
setChildren(children3, element, node)
|
|
71
|
-
expect(element.__ref.__noChildrenDifference).toBeUndefined()
|
|
72
|
-
expect(element.__ref.__childrenCache).toEqual(children3)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('handles mixed React and normal components', () => {
|
|
76
|
-
const mixedChildren = [
|
|
77
|
-
{ type: 'div', text: 'Normal' },
|
|
78
|
-
{ $$typeof: Symbol('react') },
|
|
79
|
-
{ type: 'span', text: 'Another' }
|
|
80
|
-
]
|
|
81
|
-
|
|
82
|
-
setChildren(mixedChildren, element, node)
|
|
83
|
-
|
|
84
|
-
expect(element.call).toHaveBeenCalledWith(
|
|
85
|
-
'renderReact',
|
|
86
|
-
[mixedChildren[1]],
|
|
87
|
-
element
|
|
88
|
-
)
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('handles state-based children', () => {
|
|
92
|
-
element.state = {
|
|
93
|
-
items: ['a', 'b'],
|
|
94
|
-
parse: () => ['parsed a', 'parsed b']
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const result = setChildren('state', element, node)
|
|
98
|
-
expect(result).toEqual({
|
|
99
|
-
tag: 'fragment',
|
|
100
|
-
0: { text: 'parsed a' },
|
|
101
|
-
1: { text: 'parsed b' }
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('handles async function parameters', () => {
|
|
106
|
-
const asyncParam = () => ['async1', 'async2']
|
|
107
|
-
const result = setChildren(asyncParam, element, node)
|
|
108
|
-
|
|
109
|
-
expect(result).toEqual({
|
|
110
|
-
tag: 'fragment',
|
|
111
|
-
0: { text: 'async1' },
|
|
112
|
-
1: { text: 'async2' }
|
|
113
|
-
})
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it('handles nested object structures', () => {
|
|
117
|
-
const nestedChildren = {
|
|
118
|
-
header: { text: 'Title' },
|
|
119
|
-
content: {
|
|
120
|
-
nested: { text: 'Content' }
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const result = setChildren(nestedChildren, element, node)
|
|
125
|
-
expect(result).toEqual({
|
|
126
|
-
tag: 'fragment',
|
|
127
|
-
0: { text: 'Title' },
|
|
128
|
-
1: { nested: { text: 'Content' } }
|
|
129
|
-
})
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
it('handles empty arrays and objects', () => {
|
|
133
|
-
let result = setChildren([], element, node)
|
|
134
|
-
expect(result).toEqual({
|
|
135
|
-
tag: 'fragment'
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
result = setChildren({}, element, node)
|
|
139
|
-
expect(result).toEqual({
|
|
140
|
-
tag: 'fragment'
|
|
141
|
-
})
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
it('handles falsy values in arrays', () => {
|
|
145
|
-
const result = setChildren([null, undefined, false, 0, ''], element, node)
|
|
146
|
-
expect(result).toEqual({
|
|
147
|
-
tag: 'fragment',
|
|
148
|
-
3: { text: 0 },
|
|
149
|
-
4: { text: '' }
|
|
150
|
-
})
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
it('handles React components with falsy values in array', () => {
|
|
154
|
-
const mixedChildren = [
|
|
155
|
-
null,
|
|
156
|
-
{ $$typeof: Symbol('react') },
|
|
157
|
-
undefined,
|
|
158
|
-
{ $$typeof: Symbol('react') },
|
|
159
|
-
false
|
|
160
|
-
]
|
|
161
|
-
|
|
162
|
-
setChildren(mixedChildren, element, node)
|
|
163
|
-
|
|
164
|
-
expect(element.call).toHaveBeenCalledWith(
|
|
165
|
-
'renderReact',
|
|
166
|
-
[mixedChildren[1], mixedChildren[3]],
|
|
167
|
-
element
|
|
168
|
-
)
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
it('handles nested state parsing', () => {
|
|
172
|
-
element.state = {
|
|
173
|
-
nested: {
|
|
174
|
-
items: ['c', 'd']
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
element.state.nested.__proto__.parse = () => ['parsed c', 'parsed d']
|
|
178
|
-
|
|
179
|
-
const result = setChildren('nested', element, node)
|
|
180
|
-
expect(result).toEqual({
|
|
181
|
-
tag: 'fragment',
|
|
182
|
-
0: { state: ['c', 'd'] }
|
|
183
|
-
})
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
it('handles mixed state and regular objects', () => {
|
|
187
|
-
element.state = {
|
|
188
|
-
header: { parse: () => 'Header' },
|
|
189
|
-
footer: { parse: () => 'Footer' }
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const result = setChildren(
|
|
193
|
-
{
|
|
194
|
-
header: 'header',
|
|
195
|
-
content: { text: 'Content' },
|
|
196
|
-
footer: 'footer'
|
|
197
|
-
},
|
|
198
|
-
element,
|
|
199
|
-
node
|
|
200
|
-
)
|
|
201
|
-
|
|
202
|
-
expect(result).toEqual({
|
|
203
|
-
tag: 'fragment',
|
|
204
|
-
0: { text: 'header' },
|
|
205
|
-
1: { text: 'Content' },
|
|
206
|
-
2: { text: 'footer' }
|
|
207
|
-
})
|
|
208
|
-
})
|
|
209
|
-
})
|
package/__tests__/define.test.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import define from '../define'
|
|
2
|
-
import { REGISTRY } from '../mixins'
|
|
3
|
-
|
|
4
|
-
describe('default function (registry updater)', () => {
|
|
5
|
-
let originalRegistry
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
// Save the original REGISTRY to restore after each test
|
|
9
|
-
originalRegistry = { ...REGISTRY }
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
// Restore the original REGISTRY after each test
|
|
14
|
-
Object.keys(REGISTRY).forEach(key => {
|
|
15
|
-
REGISTRY[key] = originalRegistry[key]
|
|
16
|
-
})
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('should add new params to REGISTRY when overwrite is true', () => {
|
|
20
|
-
const params = { newKey: 'newValue', anotherKey: 'anotherValue' }
|
|
21
|
-
const options = { overwrite: true }
|
|
22
|
-
|
|
23
|
-
define(params, options)
|
|
24
|
-
|
|
25
|
-
expect(REGISTRY.newKey).toBe('newValue')
|
|
26
|
-
expect(REGISTRY.anotherKey).toBe('anotherValue')
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('should not modify REGISTRY when trying to overwrite existing keys without overwrite option', () => {
|
|
30
|
-
const params = { attr: 'newValue', text: 'newText' }
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
define(params)
|
|
34
|
-
} catch (e) {
|
|
35
|
-
// Ignore the error
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
expect(REGISTRY.attr).toBe(originalRegistry.attr)
|
|
39
|
-
expect(REGISTRY.text).toBe(originalRegistry.text)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it('should overwrite existing keys when overwrite is true', () => {
|
|
43
|
-
const params = { attr: 'newValue', text: 'newText' }
|
|
44
|
-
const options = { overwrite: true }
|
|
45
|
-
|
|
46
|
-
define(params, options)
|
|
47
|
-
|
|
48
|
-
expect(REGISTRY.attr).toBe('newValue')
|
|
49
|
-
expect(REGISTRY.text).toBe('newText')
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('should handle empty params object without errors', () => {
|
|
53
|
-
const params = {}
|
|
54
|
-
const options = { overwrite: true }
|
|
55
|
-
|
|
56
|
-
expect(() => define(params, options)).not.toThrow()
|
|
57
|
-
expect(REGISTRY).toEqual(originalRegistry)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('should handle empty options object without errors', () => {
|
|
61
|
-
const params = { newKey: 'newValue' }
|
|
62
|
-
|
|
63
|
-
expect(() => define(params, {})).not.toThrow()
|
|
64
|
-
expect(REGISTRY.newKey).toBe('newValue')
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('should not add new keys when params is empty', () => {
|
|
68
|
-
const params = {}
|
|
69
|
-
const options = { overwrite: true }
|
|
70
|
-
|
|
71
|
-
define(params, options)
|
|
72
|
-
|
|
73
|
-
expect(REGISTRY).toEqual(originalRegistry)
|
|
74
|
-
})
|
|
75
|
-
})
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { update } from '../update'
|
|
2
|
-
|
|
3
|
-
describe('update() with inheritStateUpdates', () => {
|
|
4
|
-
let element, options
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
element = {
|
|
8
|
-
__ref: {
|
|
9
|
-
__state: null,
|
|
10
|
-
__hasRootState: false,
|
|
11
|
-
__execProps: {},
|
|
12
|
-
__props: []
|
|
13
|
-
},
|
|
14
|
-
state: {
|
|
15
|
-
calculated: 42,
|
|
16
|
-
set: () => {
|
|
17
|
-
return true
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
parent: {
|
|
21
|
-
state: { baseState: true },
|
|
22
|
-
props: {}
|
|
23
|
-
},
|
|
24
|
-
props: {},
|
|
25
|
-
key: 'testKey'
|
|
26
|
-
}
|
|
27
|
-
options = {}
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
// Test 1: Continue update when state inheritance succeeds
|
|
31
|
-
it('processes full update flow when state is inherited', () => {
|
|
32
|
-
update.call(element, { props: { newProp: true } }, options)
|
|
33
|
-
expect(element.props.newProp).toBe(true)
|
|
34
|
-
expect(element.state.baseState).toBe(true) // Inherited from parent
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
// Test 2: Preserve existing state when inheritance blocked
|
|
38
|
-
it('maintains state when preventInheritedStateUpdate=true', () => {
|
|
39
|
-
options.preventInheritedStateUpdate = true
|
|
40
|
-
element.state = { existing: 'state' }
|
|
41
|
-
|
|
42
|
-
update.call(element, {}, options)
|
|
43
|
-
expect(element.state).toEqual({ baseState: true })
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
// Test 3: Execute state functions when forced
|
|
47
|
-
it('overwrites state with function result', () => {
|
|
48
|
-
element.__ref.__state = () => ({ calculated: 42 })
|
|
49
|
-
options.execStateFunction = true
|
|
50
|
-
options.stateFunctionOverwrite = true
|
|
51
|
-
|
|
52
|
-
update.call(element, {}, options)
|
|
53
|
-
expect(element.state.calculated).toEqual(42)
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
// Test 4: Block updates via beforeStateUpdate event
|
|
57
|
-
it('preserves state when beforeStateUpdate rejects', () => {
|
|
58
|
-
element.onBeforeStateUpdate = () => false
|
|
59
|
-
update.call(element, { props: { shouldChange: true } }, options)
|
|
60
|
-
expect(element.state).toEqual({ baseState: true })
|
|
61
|
-
expect(element.props.shouldChange).toBe(true)
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
// Test 5: Handle parent state changes
|
|
65
|
-
it('reflects parent state updates', () => {
|
|
66
|
-
element.parent.state = { updatedParentState: true }
|
|
67
|
-
update.call(element, {}, options)
|
|
68
|
-
expect(element.state.updatedParentState).toBe(true)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
// Test 6: Maintain local state when root state exists
|
|
72
|
-
it('preserves local state when __hasRootState=true', () => {
|
|
73
|
-
element.__ref.__hasRootState = true
|
|
74
|
-
element.state = { local: 'data' }
|
|
75
|
-
|
|
76
|
-
update.call(element, {}, options)
|
|
77
|
-
expect(element.state.local).toBe('data')
|
|
78
|
-
})
|
|
79
|
-
})
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { jest } from '@jest/globals'
|
|
2
|
-
|
|
3
|
-
describe('create()', () => {
|
|
4
|
-
let props
|
|
5
|
-
let parent
|
|
6
|
-
|
|
7
|
-
const OLD_ENV = process.env
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
props = {
|
|
11
|
-
__ref: { __if: false, path: [], __skipCreate: true },
|
|
12
|
-
key: 'testKey',
|
|
13
|
-
context: {
|
|
14
|
-
defaultExtends: {},
|
|
15
|
-
define: ['test']
|
|
16
|
-
},
|
|
17
|
-
scope: 'props',
|
|
18
|
-
define: ['test']
|
|
19
|
-
}
|
|
20
|
-
parent = {
|
|
21
|
-
testKey: 'parentTestKey',
|
|
22
|
-
key: 'parentKey'
|
|
23
|
-
}
|
|
24
|
-
jest.resetModules()
|
|
25
|
-
process.env = { ...OLD_ENV }
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
afterAll(() => {
|
|
29
|
-
process.env = OLD_ENV
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
test('should execute onlyResolveExtends when __skipCreate is true', async () => {
|
|
33
|
-
props.__ref.__skipCreate = true
|
|
34
|
-
props.scope = undefined
|
|
35
|
-
const { create } = await import('../create')
|
|
36
|
-
create(props, parent, 'passedKey', {
|
|
37
|
-
onlyResolveExtends: true,
|
|
38
|
-
define: ['test']
|
|
39
|
-
})
|
|
40
|
-
expect(parent.__ref).toBeUndefined()
|
|
41
|
-
expect(parent.passedKey).toBe(props.__ref.parent.passedKey)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
test('should execute onlyResolveExtends when __ref.__if is true', async () => {
|
|
45
|
-
props.__ref.__if = true
|
|
46
|
-
props.scope = 'state'
|
|
47
|
-
const { create } = await import('../create')
|
|
48
|
-
create(props, parent, 'passedKey', {
|
|
49
|
-
onlyResolveExtends: true,
|
|
50
|
-
define: ['test']
|
|
51
|
-
})
|
|
52
|
-
expect(parent.__ref).toBeUndefined()
|
|
53
|
-
expect(parent.passedKey).toBe(props.__ref.parent.passedKey)
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
test('should execute onlyResolveExtends when scope is not state', async () => {
|
|
57
|
-
process.env.NODE_ENV = 'prod'
|
|
58
|
-
props.__ref = undefined
|
|
59
|
-
const { create } = await import('../create')
|
|
60
|
-
create(props, parent, 'passedKey', { onlyResolveExtends: true })
|
|
61
|
-
expect(parent.__ref).toBeUndefined()
|
|
62
|
-
expect(parent.passedKey).toBe(props.__ref.parent.passedKey)
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
test('should execute catch statement when __ref is undefined', async () => {
|
|
66
|
-
process.env.NODE_ENV = 'prod'
|
|
67
|
-
props.__ref = undefined
|
|
68
|
-
const { create } = await import('../create')
|
|
69
|
-
create(props, parent, 'passedKey')
|
|
70
|
-
expect(parent.__ref).toBeUndefined()
|
|
71
|
-
expect(parent.passedKey).toBe(props.__ref.parent.passedKey)
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
test('should attaches element to parent when ref.__if is false', async () => {
|
|
75
|
-
process.env.NODE_ENV = 'prod'
|
|
76
|
-
const { create } = await import('../create')
|
|
77
|
-
create(props, parent, 'passedKey')
|
|
78
|
-
expect(parent.__ref).toBeUndefined()
|
|
79
|
-
expect(parent.passedKey).toBe(props.__ref.parent.passedKey)
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
test('should attach element to parent when ref.__if is true', async () => {
|
|
83
|
-
process.env.NODE_ENV = 'prod'
|
|
84
|
-
props.__if = true
|
|
85
|
-
const { create } = await import('../create')
|
|
86
|
-
create(props, parent, 'passedKey')
|
|
87
|
-
expect(parent.testKey).toBe('parentTestKey')
|
|
88
|
-
expect(parent.passedKey).toBe(props.__ref.parent.passedKey)
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
test('skips createNestedChild when __uniqId exists', async () => {
|
|
92
|
-
process.env.NODE_ENV = 'prod'
|
|
93
|
-
props.__ref = { __uniqId: 'existing-id', path: [] }
|
|
94
|
-
const { create } = await import('../create')
|
|
95
|
-
create(props, {}, 'passedKey')
|
|
96
|
-
expect(props.__ref.__uniqId).toBeDefined()
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
test('skips createNestedChild when infinite loop detected', async () => {
|
|
100
|
-
process.env.NODE_ENV = 'prod'
|
|
101
|
-
props.__ref = { path: ['loop-path'], __uniqId: undefined }
|
|
102
|
-
const { create } = await import('../create')
|
|
103
|
-
create(props, {}, 'passedKey')
|
|
104
|
-
expect(props.__ref.__uniqId).toBeDefined()
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
test('should modifies path containing ComponentsGrid', async () => {
|
|
108
|
-
process.env.NODE_ENV = 'prod'
|
|
109
|
-
props.__ref = { path: ['ComponentsGrid', 'x', 'y', 'z'] }
|
|
110
|
-
const { create } = await import('../create')
|
|
111
|
-
create(props, {}, ['ComponentsGrid', 'x', 'y', 'z'])
|
|
112
|
-
expect(props.__ref.path).toEqual(['ComponentsGrid,x,y,z'])
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
test('should modifies path containing demoComponent', async () => {
|
|
116
|
-
process.env.NODE_ENV = 'prod'
|
|
117
|
-
props.__ref = { path: ['demoComponent', 'a', 'b', 'c'] }
|
|
118
|
-
const { create } = await import('../create')
|
|
119
|
-
create(props, {}, ['demoComponent', 'a', 'b', 'c'])
|
|
120
|
-
expect(props.__ref.path).toEqual(['demoComponent,a,b,c'])
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
test('uses element.key when key property is missing', async () => {
|
|
124
|
-
process.env.NODE_ENV = 'prod'
|
|
125
|
-
props.__ref = { __if: false, path: [] }
|
|
126
|
-
props.key = 'fallbackKey'
|
|
127
|
-
const { create } = await import('../create')
|
|
128
|
-
create(props, parent, null)
|
|
129
|
-
expect(props.__ref.parent.fallbackKey).toBeDefined()
|
|
130
|
-
})
|
|
131
|
-
})
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { resetContent } from '../set'
|
|
2
|
-
|
|
3
|
-
describe('resetContent', () => {
|
|
4
|
-
let element, ref
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
ref = {
|
|
8
|
-
contentElementKey: 'content'
|
|
9
|
-
}
|
|
10
|
-
element = {
|
|
11
|
-
__ref: ref,
|
|
12
|
-
content: { node: document.createElement('div') },
|
|
13
|
-
node: document.createElement('div'),
|
|
14
|
-
context: {}
|
|
15
|
-
}
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it('should update contentElementKey from options', () => {
|
|
19
|
-
resetContent({}, element, { contentElementKey: 'mainContent' })
|
|
20
|
-
|
|
21
|
-
expect(ref.contentElementKey).toBe('mainContent')
|
|
22
|
-
expect(element.mainContent).toBeDefined()
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('should merge options correctly', () => {
|
|
26
|
-
resetContent({}, element, { customOption: true })
|
|
27
|
-
|
|
28
|
-
expect(element.content).toEqual(
|
|
29
|
-
expect.objectContaining({
|
|
30
|
-
// Verify options merging through observable behavior
|
|
31
|
-
// (this assertion pattern would need actual create() implementation details)
|
|
32
|
-
})
|
|
33
|
-
)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('should maintain context through reset', () => {
|
|
37
|
-
const originalContext = element.context
|
|
38
|
-
|
|
39
|
-
resetContent({}, element, {})
|
|
40
|
-
|
|
41
|
-
expect(element.context).toBe(originalContext)
|
|
42
|
-
expect(element.content.context).toBe(originalContext)
|
|
43
|
-
})
|
|
44
|
-
})
|