diff --git a/docs/API.md b/docs/API.md index f861cdf57..00a10f9c0 100644 --- a/docs/API.md +++ b/docs/API.md @@ -137,8 +137,10 @@ mount(Component, { } }) ``` - -### `mixins` +### Global +You can provide properties to the App instance using the properties under the `global` mount property + +### `global.mixins` Applies mixins via `app.mixin(...)`. @@ -161,14 +163,16 @@ test('adds a lifecycle mixin', () => { } const wrapper = mount(Component, { - mixins: [mixin] + global: { + mixins: [mixin] + } }) // 'Component was created!' will be logged }) ``` -### `plugins` +### `global.plugins` Installs plugins on the component. @@ -194,7 +198,9 @@ test('installs a plugin via `plugins`', () => { render() { return h('div') } } mount(Component, { - plugins: [Plugin] + global: { + plugins: [Plugin] + } }) expect(installed).toHaveBeenCalled() diff --git a/src/mount.ts b/src/mount.ts index 854b00969..adf0273c1 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -1,4 +1,11 @@ -import { h, createApp, VNode, defineComponent } from 'vue' +import { + h, + createApp, + VNode, + defineComponent, + Plugin, + ComponentOptions +} from 'vue' import { VueWrapper, createWrapper } from './vue-wrapper' import { createEmitMixin } from './emitMixin' @@ -13,8 +20,10 @@ interface MountingOptions { default?: Slot [key: string]: Slot } - plugins?: any[] - mixins?: any[] + global?: { + plugins?: Plugin[] + mixins?: ComponentOptions[] + } provides?: Record stubs?: Record } @@ -59,13 +68,13 @@ export function mount

( const vm = createApp(Parent(options && options.props)) // use and plugins from mounting options - if (options?.plugins) { - for (const use of options.plugins) vm.use(use) + if (options?.global?.plugins) { + for (const use of options?.global?.plugins) vm.use(use) } // use any mixins from mounting options - if (options?.mixins) { - for (const mixin of options.mixins) vm.mixin(mixin) + if (options?.global?.mixins) { + for (const mixin of options?.global?.mixins) vm.mixin(mixin) } // provide any values passed via provides mounting option diff --git a/tests/mountingOptions/mixins.spec.ts b/tests/mountingOptions/mixins.spec.ts index d65239dca..92de68ae1 100644 --- a/tests/mountingOptions/mixins.spec.ts +++ b/tests/mountingOptions/mixins.spec.ts @@ -11,13 +11,17 @@ describe('mounting options: mixins', () => { } } const Component = { - render() { return h('div') } + render() { + return h('div') + } } mount(Component, { - mixins: [mixin] + global: { + mixins: [mixin] + } }) expect(createdHook).toHaveBeenCalled() }) -}) \ No newline at end of file +}) diff --git a/tests/mountingOptions/plugins.spec.ts b/tests/mountingOptions/plugins.spec.ts index fd0aea7b7..7c33c485b 100644 --- a/tests/mountingOptions/plugins.spec.ts +++ b/tests/mountingOptions/plugins.spec.ts @@ -5,18 +5,24 @@ import { mount } from '../../src' describe('mounting options: plugins', () => { it('installs a plugin via `plugins`', () => { const installed = jest.fn() + class Plugin { static install() { installed() } } + const Component = { - render() { return h('div') } + render() { + return h('div') + } } mount(Component, { - plugins: [Plugin] + global: { + plugins: [Plugin] + } }) expect(installed).toHaveBeenCalled() }) -}) \ No newline at end of file +})