fix(runtime-core): test cases for mixing composition/options api

This commit is contained in:
xieyuschen 2024-08-21 18:01:33 +08:00
parent 7704d78a34
commit 3e21461ca0
1 changed files with 86 additions and 0 deletions

View File

@ -0,0 +1,86 @@
import { defineComponent, h, renderToString } from '@vue/runtime-test'
describe('api: options', () => {
test('mix api options: setup and data with created', () => {
const mixinA = defineComponent({
setup() {
return {
a: 'from setup',
}
},
data() {
return {
a: 'from data',
}
},
created(this: any) {
this.a = 'from created'
},
render() {
return `${this.a}`
},
})
expect(renderToString(h(mixinA))).toBe(`from created`)
})
test('mix api options: data and setup with created', () => {
const mixinA = defineComponent({
data() {
return {
a: 'from data',
}
},
setup() {
return {
a: 'from setup',
}
},
created(this: any) {
this.a = 'from created'
},
render() {
return `${this.a}`
},
})
expect(renderToString(h(mixinA))).toBe(`from created`)
})
test('mix api options: data and setup', () => {
const mixinA = defineComponent({
data() {
return {
a: 'from data',
}
},
setup() {
return {
a: 'from setup',
}
},
created(this: any) {},
render() {
return `${this.a}`
},
})
expect(renderToString(h(mixinA))).toBe(`from setup`)
})
test('mix api options: setup and data', () => {
const mixinA = defineComponent({
setup() {
return {
a: 'from setup',
}
},
data() {
return {
a: 'from data',
}
},
render() {
return `${this.a}`
},
})
expect(renderToString(h(mixinA))).toBe(`from setup`)
})
})