Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 3430bff

Browse files
authored
test(runtime-core): test cases when the value of the $stable flag is false (#11485)
1 parent 33cd613 commit 3430bff

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

packages/runtime-core/__tests__/componentSlots.spec.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ describe('component: slots', () => {
213213
expect(instance.slots.default()).toMatchObject([normalizeVNode('footer')])
214214
})
215215

216-
test('should respect $stable flag', async () => {
216+
test('should respect $stable flag with a value of true', async () => {
217217
const flag1 = ref(1)
218218
const flag2 = ref(2)
219219
const spy = vi.fn()
@@ -255,6 +255,48 @@ describe('component: slots', () => {
255255
expect(spy).toHaveBeenCalledTimes(2)
256256
})
257257

258+
test('should respect $stable flag with a value of false', async () => {
259+
const flag1 = ref(1)
260+
const flag2 = ref(2)
261+
const spy = vi.fn()
262+
263+
const Child = () => {
264+
spy()
265+
return 'child'
266+
}
267+
268+
const App = {
269+
setup() {
270+
return () => [
271+
flag1.value,
272+
h(
273+
Child,
274+
{ n: flag2.value },
275+
{
276+
foo: () => 'foo',
277+
$stable: false,
278+
},
279+
),
280+
]
281+
},
282+
}
283+
284+
render(h(App), nodeOps.createElement('div'))
285+
expect(spy).toHaveBeenCalledTimes(1)
286+
287+
// parent re-render, props didn't change, slots are not stable
288+
// -> child should update
289+
flag1.value++
290+
await nextTick()
291+
expect(spy).toHaveBeenCalledTimes(2)
292+
293+
// parent re-render, props changed
294+
// -> child should update
295+
flag2.value++
296+
await nextTick()
297+
expect(spy).toHaveBeenCalledTimes(3)
298+
})
299+
258300
test('should not warn when mounting another app in setup', () => {
259301
const Comp = {
260302
setup(_: any, { slots }: any) {

0 commit comments

Comments
 (0)