fix(inject): fix support for inject option default function

fix #2050
This commit is contained in:
Evan You
2020-09-04 12:00:37 -04:00
parent 6dbc6c4cd0
commit d4724619fc
3 changed files with 47 additions and 42 deletions

View File

@@ -241,7 +241,7 @@ describe('api: options', () => {
})
test('provide/inject', () => {
const Root = {
const Root = defineComponent({
data() {
return {
a: 1
@@ -253,45 +253,38 @@ describe('api: options', () => {
}
},
render() {
return [h(ChildA), h(ChildB), h(ChildC), h(ChildD)]
return [h(ChildA), h(ChildB), h(ChildC), h(ChildD), h(ChildE)]
}
} as any
const ChildA = {
inject: ['a'],
render() {
return this.a
}
} as any
const ChildB = {
// object alias
inject: { b: 'a' },
render() {
return this.b
}
} as any
const ChildC = {
inject: {
b: {
from: 'a'
}
},
render() {
return this.b
}
} as any
const ChildD = {
inject: {
b: {
from: 'c',
default: 2
}
},
render() {
return this.b
}
} as any
})
expect(renderToString(h(Root))).toBe(`1112`)
const defineChild = (injectOptions: any, injectedKey = 'b') =>
({
inject: injectOptions,
render() {
return this[injectedKey]
}
} as any)
const ChildA = defineChild(['a'], 'a')
const ChildB = defineChild({ b: 'a' })
const ChildC = defineChild({
b: {
from: 'a'
}
})
const ChildD = defineChild({
b: {
from: 'c',
default: 2
}
})
const ChildE = defineChild({
b: {
from: 'c',
default: () => 3
}
})
expect(renderToString(h(Root))).toBe(`11123`)
})
test('lifecycle', async () => {