diff --git a/docs/API.md b/docs/API.md index 7368312cc..3152aa505 100644 --- a/docs/API.md +++ b/docs/API.md @@ -190,7 +190,7 @@ export default {} test('installs a plugin via `plugins`', () => { const installed = jest.fn() class Plugin { - static install() { + static install(app: App, options?: any) { installed() } } @@ -199,7 +199,7 @@ test('installs a plugin via `plugins`', () => { } mount(Component, { global: { - plugins: [Plugin] + plugins: [{ plugin: Plugin, options: {} }] } }) diff --git a/src/mount.ts b/src/mount.ts index 8a46f4343..85f83a124 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -312,7 +312,7 @@ export function mount( // use and plugins from mounting options if (global.plugins) { - for (const use of global.plugins) app.use(use) + for (const { plugin, options } of global.plugins) app.use(plugin, options) } // use any mixins from mounting options diff --git a/src/types.ts b/src/types.ts index 7d9d3fafc..d02e13a09 100644 --- a/src/types.ts +++ b/src/types.ts @@ -20,7 +20,7 @@ export type FindComponentSelector = RefSelector | NameSelector | string export type FindAllComponentsSelector = NameSelector | string export type GlobalMountOptions = { - plugins?: Plugin[] + plugins?: { plugin: Plugin; options?: any }[] config?: Omit // isNativeTag is readonly, so we omit it mixins?: ComponentOptions[] mocks?: Record diff --git a/tests/features/vuex.spec.ts b/tests/features/vuex.spec.ts index 5e1072638..cf652eb92 100644 --- a/tests/features/vuex.spec.ts +++ b/tests/features/vuex.spec.ts @@ -30,7 +30,7 @@ describe('vuex', () => { const wrapper = mount(Foo, { global: { - plugins: [store] + plugins: [{ plugin: store }] } }) diff --git a/tests/mountingOptions/global.plugins.spec.ts b/tests/mountingOptions/global.plugins.spec.ts index 7c33c485b..eaf75f41f 100644 --- a/tests/mountingOptions/global.plugins.spec.ts +++ b/tests/mountingOptions/global.plugins.spec.ts @@ -1,4 +1,4 @@ -import { h } from 'vue' +import { h, App } from 'vue' import { mount } from '../../src' @@ -19,10 +19,34 @@ describe('mounting options: plugins', () => { } mount(Component, { global: { - plugins: [Plugin] + plugins: [{ plugin: Plugin }] } }) expect(installed).toHaveBeenCalled() }) + + it('installs a plugin with options `plugins`', () => { + const installed = jest.fn() + + class Plugin { + static install(_app: App, options: { option1: boolean }) { + installed(options) + } + } + + const Component = { + render() { + return h('div') + } + } + const options = { option1: true } + mount(Component, { + global: { + plugins: [{ plugin: Plugin, options }] + } + }) + + expect(installed).toHaveBeenCalledWith(options) + }) })