Merge remote-tracking branch 'github/master' into changing_unwrap_ref
# Conflicts: # packages/reactivity/src/ref.ts # packages/runtime-core/__tests__/apiTemplateRef.spec.ts # packages/runtime-core/src/apiWatch.ts
This commit is contained in:
@@ -4,7 +4,9 @@ import {
|
||||
h,
|
||||
render,
|
||||
nextTick,
|
||||
createComponent
|
||||
Ref,
|
||||
defineComponent,
|
||||
reactive
|
||||
} from '@vue/runtime-test'
|
||||
|
||||
// reference: https://vue-composition-api-rfc.netlify.com/api.html#template-refs
|
||||
@@ -82,7 +84,7 @@ describe('api: template refs', () => {
|
||||
const root = nodeOps.createElement('div')
|
||||
const fn = jest.fn()
|
||||
|
||||
const Comp = createComponent(() => () => h('div', { ref: fn }))
|
||||
const Comp = defineComponent(() => () => h('div', { ref: fn }))
|
||||
render(h(Comp), root)
|
||||
expect(fn.mock.calls[0][0]).toBe(root.children[0])
|
||||
})
|
||||
@@ -93,7 +95,7 @@ describe('api: template refs', () => {
|
||||
const fn2 = jest.fn()
|
||||
const fn = ref(fn1)
|
||||
|
||||
const Comp = createComponent(() => () => h('div', { ref: fn.value }))
|
||||
const Comp = defineComponent(() => () => h('div', { ref: fn.value }))
|
||||
|
||||
render(h(Comp), root)
|
||||
expect(fn1.mock.calls).toHaveLength(1)
|
||||
@@ -112,7 +114,7 @@ describe('api: template refs', () => {
|
||||
const fn = jest.fn()
|
||||
const toggle = ref(true)
|
||||
|
||||
const Comp = createComponent(() => () =>
|
||||
const Comp = defineComponent(() => () =>
|
||||
toggle.value ? h('div', { ref: fn }) : null
|
||||
)
|
||||
render(h(Comp), root)
|
||||
@@ -175,4 +177,46 @@ describe('api: template refs', () => {
|
||||
await nextTick()
|
||||
expect(el.value).toBe(null)
|
||||
})
|
||||
|
||||
test('string ref inside slots', async () => {
|
||||
const root = nodeOps.createElement('div')
|
||||
const spy = jest.fn()
|
||||
const Child = {
|
||||
render(this: any) {
|
||||
return this.$slots.default()
|
||||
}
|
||||
}
|
||||
|
||||
const Comp = {
|
||||
render() {
|
||||
return h(Child, () => {
|
||||
return h('div', { ref: 'foo' })
|
||||
})
|
||||
},
|
||||
mounted(this: any) {
|
||||
spy(this.$refs.foo.tag)
|
||||
}
|
||||
}
|
||||
render(h(Comp), root)
|
||||
|
||||
expect(spy).toHaveBeenCalledWith('div')
|
||||
})
|
||||
|
||||
it('should work with direct reactive property', () => {
|
||||
const root = nodeOps.createElement('div')
|
||||
const state = reactive({
|
||||
refKey: null
|
||||
})
|
||||
|
||||
const Comp = {
|
||||
setup() {
|
||||
return state
|
||||
},
|
||||
render() {
|
||||
return h('div', { ref: 'refKey' })
|
||||
}
|
||||
}
|
||||
render(h(Comp), root)
|
||||
expect(state.refKey).toBe(root.children[0])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user