Skip to content

Commit 078e456

Browse files
committed
allow passing options to plugins
1 parent 4139219 commit 078e456

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

docs/API.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export default {}
190190
test('installs a plugin via `plugins`', () => {
191191
const installed = jest.fn()
192192
class Plugin {
193-
static install() {
193+
static install(app: App, options?: any) {
194194
installed()
195195
}
196196
}
@@ -199,7 +199,7 @@ test('installs a plugin via `plugins`', () => {
199199
}
200200
mount(Component, {
201201
global: {
202-
plugins: [Plugin]
202+
plugins: [{ plugin: Plugin, options: {} }]
203203
}
204204
})
205205

src/mount.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export function mount(
312312

313313
// use and plugins from mounting options
314314
if (global.plugins) {
315-
for (const use of global.plugins) app.use(use)
315+
for (const { plugin, options } of global.plugins) app.use(plugin, options)
316316
}
317317

318318
// use any mixins from mounting options

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type FindComponentSelector = RefSelector | NameSelector | string
2020
export type FindAllComponentsSelector = NameSelector | string
2121

2222
export type GlobalMountOptions = {
23-
plugins?: Plugin[]
23+
plugins?: { plugin: Plugin; options?: any }[]
2424
config?: Omit<AppConfig, 'isNativeTag'> // isNativeTag is readonly, so we omit it
2525
mixins?: ComponentOptions[]
2626
mocks?: Record<string, any>

tests/features/vuex.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('vuex', () => {
3030

3131
const wrapper = mount(Foo, {
3232
global: {
33-
plugins: [store]
33+
plugins: [{ plugin: store }]
3434
}
3535
})
3636

tests/mountingOptions/global.plugins.spec.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h } from 'vue'
1+
import { h, App } from 'vue'
22

33
import { mount } from '../../src'
44

@@ -19,10 +19,34 @@ describe('mounting options: plugins', () => {
1919
}
2020
mount(Component, {
2121
global: {
22-
plugins: [Plugin]
22+
plugins: [{ plugin: Plugin }]
2323
}
2424
})
2525

2626
expect(installed).toHaveBeenCalled()
2727
})
28+
29+
it('installs a plugin with options `plugins`', () => {
30+
const installed = jest.fn()
31+
32+
class Plugin {
33+
static install(_app: App, options: { option1: boolean }) {
34+
installed(options)
35+
}
36+
}
37+
38+
const Component = {
39+
render() {
40+
return h('div')
41+
}
42+
}
43+
const options = { option1: true }
44+
mount(Component, {
45+
global: {
46+
plugins: [{ plugin: Plugin, options }]
47+
}
48+
})
49+
50+
expect(installed).toHaveBeenCalledWith(options)
51+
})
2852
})

0 commit comments

Comments
 (0)