@@ -9,7 +9,8 @@ import {
|
||||
renderToString,
|
||||
ref,
|
||||
defineComponent,
|
||||
createApp
|
||||
createApp,
|
||||
computed
|
||||
} from '@vue/runtime-test'
|
||||
|
||||
describe('api: options', () => {
|
||||
@@ -426,6 +427,69 @@ describe('api: options', () => {
|
||||
expect(renderToString(h(Root))).toBe(`1111234522`)
|
||||
})
|
||||
|
||||
test('provide/inject refs', async () => {
|
||||
const n = ref(0)
|
||||
const np = computed(() => n.value + 1)
|
||||
const Parent = defineComponent({
|
||||
provide() {
|
||||
return {
|
||||
n,
|
||||
np
|
||||
}
|
||||
},
|
||||
render: () => h(Child)
|
||||
})
|
||||
const Child = defineComponent({
|
||||
inject: ['n', 'np'],
|
||||
render(this: any) {
|
||||
return this.n + this.np
|
||||
}
|
||||
})
|
||||
const app = createApp(Parent)
|
||||
// TODO remove in 3.3
|
||||
app.config.unwrapInjectedRef = true
|
||||
const root = nodeOps.createElement('div')
|
||||
app.mount(root)
|
||||
expect(serializeInner(root)).toBe(`1`)
|
||||
|
||||
n.value++
|
||||
await nextTick()
|
||||
expect(serializeInner(root)).toBe(`3`)
|
||||
})
|
||||
|
||||
// TODO remove in 3.3
|
||||
test('provide/inject refs (compat)', async () => {
|
||||
const n = ref(0)
|
||||
const np = computed(() => n.value + 1)
|
||||
const Parent = defineComponent({
|
||||
provide() {
|
||||
return {
|
||||
n,
|
||||
np
|
||||
}
|
||||
},
|
||||
render: () => h(Child)
|
||||
})
|
||||
const Child = defineComponent({
|
||||
inject: ['n', 'np'],
|
||||
render(this: any) {
|
||||
return this.n.value + this.np.value
|
||||
}
|
||||
})
|
||||
const app = createApp(Parent)
|
||||
|
||||
const root = nodeOps.createElement('div')
|
||||
app.mount(root)
|
||||
expect(serializeInner(root)).toBe(`1`)
|
||||
|
||||
n.value++
|
||||
await nextTick()
|
||||
expect(serializeInner(root)).toBe(`3`)
|
||||
|
||||
expect(`injected property "n" is a ref`).toHaveBeenWarned()
|
||||
expect(`injected property "np" is a ref`).toHaveBeenWarned()
|
||||
})
|
||||
|
||||
test('provide accessing data in extends', () => {
|
||||
const Base = defineComponent({
|
||||
data() {
|
||||
|
||||
Reference in New Issue
Block a user