expect(`already been mounted`).toHaveBeenWarned()
})
+ test('unmount', () => {
+ const Comp = {
+ props: {
+ count: {
+ default: 0
+ }
+ },
+ setup(props: { count: number }) {
+ return () => props.count
+ }
+ }
+
+ const root = nodeOps.createElement('div')
+ const app = createApp()
+ app.mount(Comp, root)
+
+ app.unmount(root)
+ expect(serializeInner(root)).toBe(``)
+ })
+
test('provide', () => {
const app = createApp()
app.provide('foo', 1)
rootContainer: HostElement | string,
rootProps?: Data
): ComponentPublicInstance
+ unmount(rootContainer: HostElement | string): void
provide<T>(key: InjectionKey<T> | string, value: T): this
}
}
},
+ unmount(rootContainer: HostElement) {
+ render(null, rootContainer)
+ },
+
provide(key, value) {
if (__DEV__ && key in context.provides) {
warn(
})
}
- const mount = app.mount
+ const { mount, unmount } = app
app.mount = (component, container, props): any => {
if (isString(container)) {
container = document.querySelector(container)!
return mount(component, container, props)
}
+ app.unmount = container => {
+ if (isString(container)) {
+ container = document.querySelector(container)!
+ if (!container) {
+ __DEV__ &&
+ warn(`Failed to unmount app: mount target selector returned null.`)
+ return
+ }
+ }
+ unmount(container)
+ }
+
return app
}