Skip to content

Commit 9291afe

Browse files
committed
chore: update test case
1 parent 45403e3 commit 9291afe

File tree

2 files changed

+58
-31
lines changed

2 files changed

+58
-31
lines changed

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

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
setBlockTracking,
3030
withCtx,
3131
} from '@vue/runtime-test'
32-
import { PatchFlags, SlotFlags } from '@vue/shared'
32+
import { PatchFlags, SlotFlags, toDisplayString } from '@vue/shared'
3333
import { SuspenseImpl } from '../src/components/Suspense'
3434

3535
describe('renderer: optimized mode', () => {
@@ -270,6 +270,63 @@ describe('renderer: optimized mode', () => {
270270
)
271271
})
272272

273+
test('PatchFlags: PatchFlags.STABLE_FRAGMENT with change array item', async () => {
274+
const count = ref(0)
275+
const foo: any = []
276+
function updateFoo() {
277+
for (let n = 0; n < 3; n++) {
278+
foo[n] = n + 1 + '_foo'
279+
}
280+
}
281+
const Comp = {
282+
setup() {
283+
return () => {
284+
// <div>{{ count }}</div>
285+
// <div v-for='item in foo'>{{ item }}</div>
286+
return (
287+
openBlock(),
288+
createElementBlock(
289+
Fragment,
290+
null,
291+
[
292+
createElementVNode(
293+
'div',
294+
null,
295+
toDisplayString(count.value),
296+
1 /* TEXT */,
297+
),
298+
(openBlock(),
299+
createElementBlock(
300+
Fragment,
301+
null,
302+
renderList(foo, item => {
303+
return createElementVNode(
304+
'div',
305+
null,
306+
toDisplayString(item),
307+
1 /* TEXT */,
308+
)
309+
}),
310+
64 /* STABLE_FRAGMENT */,
311+
)),
312+
],
313+
64 /* STABLE_FRAGMENT */,
314+
)
315+
)
316+
}
317+
},
318+
}
319+
320+
render(h(Comp), root)
321+
expect(inner(root)).toBe('<div>0</div>')
322+
updateFoo()
323+
count.value++
324+
await nextTick()
325+
expect(inner(root)).toBe(
326+
'<div>1</div><div>1_foo</div><div>2_foo</div><div>3_foo</div>',
327+
)
328+
})
329+
273330
// A Fragment with `UNKEYED_FRAGMENT` flag will always patch its children,
274331
// so there's no need for tracking dynamicChildren.
275332
test('PatchFlags: PatchFlags.UNKEYED_FRAGMENT', async () => {

packages/vue/__tests__/index.spec.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -311,34 +311,4 @@ describe('compiler + runtime integration', () => {
311311
app.mount(root)
312312
expect(root.innerHTML).toBe('<div>60000000100000111</div>')
313313
})
314-
315-
test('should correctly update when reactive state and normal array are modified', async () => {
316-
const count = ref(0)
317-
const foo: any[] = []
318-
function updateFoo() {
319-
for (let n = 0; n < 3; n++) {
320-
foo[n] = n + 1 + '_foo'
321-
}
322-
}
323-
const app = createApp({
324-
setup() {
325-
return {
326-
count,
327-
foo,
328-
}
329-
},
330-
template: `
331-
<div>{{count}}</div>
332-
<div v-for='item in foo'>{{ item }}</div>`,
333-
})
334-
const root = document.createElement('div')
335-
app.mount(root)
336-
expect(root.innerHTML).toBe('<div>0</div>')
337-
updateFoo()
338-
count.value++
339-
await nextTick()
340-
expect(root.innerHTML).toBe(
341-
'<div>1</div><div>1_foo</div><div>2_foo</div><div>3_foo</div>',
342-
)
343-
})
344314
})

0 commit comments

Comments
 (0)