refactor: adjust createApp related API signatures
BREAKING CHANGE: `createApp` API has been adjusted.
- `createApp()` now accepts the root component, and optionally a props
object to pass to the root component.
- `app.mount()` now accepts a single argument (the root container)
- `app.unmount()` no longer requires arguments.
New behavior looks like the following:
``` js
const app = createApp(RootComponent)
app.mount('#app')
app.unmount()
```
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { createApp, getCurrentInstance, nodeOps } from '@vue/runtime-test'
|
||||
import { h, render, getCurrentInstance, nodeOps } from '@vue/runtime-test'
|
||||
import { mockWarn } from '@vue/shared'
|
||||
import { ComponentInternalInstance } from '../src/component'
|
||||
|
||||
@@ -6,7 +6,6 @@ describe('component: proxy', () => {
|
||||
mockWarn()
|
||||
|
||||
test('data', () => {
|
||||
const app = createApp()
|
||||
let instance: ComponentInternalInstance
|
||||
let instanceProxy: any
|
||||
const Comp = {
|
||||
@@ -23,14 +22,13 @@ describe('component: proxy', () => {
|
||||
return null
|
||||
}
|
||||
}
|
||||
app.mount(Comp, nodeOps.createElement('div'))
|
||||
render(h(Comp), nodeOps.createElement('div'))
|
||||
expect(instanceProxy.foo).toBe(1)
|
||||
instanceProxy.foo = 2
|
||||
expect(instance!.data.foo).toBe(2)
|
||||
})
|
||||
|
||||
test('renderContext', () => {
|
||||
const app = createApp()
|
||||
let instance: ComponentInternalInstance
|
||||
let instanceProxy: any
|
||||
const Comp = {
|
||||
@@ -47,14 +45,13 @@ describe('component: proxy', () => {
|
||||
return null
|
||||
}
|
||||
}
|
||||
app.mount(Comp, nodeOps.createElement('div'))
|
||||
render(h(Comp), nodeOps.createElement('div'))
|
||||
expect(instanceProxy.foo).toBe(1)
|
||||
instanceProxy.foo = 2
|
||||
expect(instance!.renderContext.foo).toBe(2)
|
||||
})
|
||||
|
||||
test('propsProxy', () => {
|
||||
const app = createApp()
|
||||
let instance: ComponentInternalInstance
|
||||
let instanceProxy: any
|
||||
const Comp = {
|
||||
@@ -72,7 +69,7 @@ describe('component: proxy', () => {
|
||||
instanceProxy = this
|
||||
}
|
||||
}
|
||||
app.mount(Comp, nodeOps.createElement('div'))
|
||||
render(h(Comp), nodeOps.createElement('div'))
|
||||
expect(instanceProxy.foo).toBe(1)
|
||||
expect(instance!.propsProxy!.foo).toBe(1)
|
||||
expect(() => (instanceProxy.foo = 2)).toThrow(TypeError)
|
||||
@@ -80,7 +77,6 @@ describe('component: proxy', () => {
|
||||
})
|
||||
|
||||
test('public properties', () => {
|
||||
const app = createApp()
|
||||
let instance: ComponentInternalInstance
|
||||
let instanceProxy: any
|
||||
const Comp = {
|
||||
@@ -92,7 +88,7 @@ describe('component: proxy', () => {
|
||||
instanceProxy = this
|
||||
}
|
||||
}
|
||||
app.mount(Comp, nodeOps.createElement('div'))
|
||||
render(h(Comp), nodeOps.createElement('div'))
|
||||
expect(instanceProxy.$data).toBe(instance!.data)
|
||||
expect(instanceProxy.$props).toBe(instance!.propsProxy)
|
||||
expect(instanceProxy.$attrs).toBe(instance!.attrs)
|
||||
@@ -108,7 +104,6 @@ describe('component: proxy', () => {
|
||||
})
|
||||
|
||||
test('sink', async () => {
|
||||
const app = createApp()
|
||||
let instance: ComponentInternalInstance
|
||||
let instanceProxy: any
|
||||
const Comp = {
|
||||
@@ -120,14 +115,13 @@ describe('component: proxy', () => {
|
||||
instanceProxy = this
|
||||
}
|
||||
}
|
||||
app.mount(Comp, nodeOps.createElement('div'))
|
||||
render(h(Comp), nodeOps.createElement('div'))
|
||||
instanceProxy.foo = 1
|
||||
expect(instanceProxy.foo).toBe(1)
|
||||
expect(instance!.sink.foo).toBe(1)
|
||||
})
|
||||
|
||||
test('has check', () => {
|
||||
const app = createApp()
|
||||
let instanceProxy: any
|
||||
const Comp = {
|
||||
render() {},
|
||||
@@ -148,7 +142,7 @@ describe('component: proxy', () => {
|
||||
instanceProxy = this
|
||||
}
|
||||
}
|
||||
app.mount(Comp, nodeOps.createElement('div'), { msg: 'hello' })
|
||||
render(h(Comp, { msg: 'hello' }), nodeOps.createElement('div'))
|
||||
|
||||
// props
|
||||
expect('msg' in instanceProxy).toBe(true)
|
||||
|
||||
Reference in New Issue
Block a user