@@ -4,6 +4,7 @@ import { RouterLinkStub, type VueWrapper } from '@vue/test-utils';
4
4
import type { bindTestingPinia } from './bindTestingPinia' ;
5
5
6
6
interface MountOptions {
7
+ testingPinia ?: ReturnType < typeof bindTestingPinia > ;
7
8
attachTo ?: Element | string ;
8
9
props ?: Record < string , unknown > ;
9
10
slots ?: Record < string , ( ) => VNode | VNode [ ] | string > | Slots ;
@@ -18,6 +19,7 @@ const DEFAULT_STUBS = {
18
19
} as const ;
19
20
20
21
const DEFAULT_OPTIONS = {
22
+ testingPinia : undefined ,
21
23
attachTo : undefined ,
22
24
props : { } ,
23
25
slots : { } ,
@@ -33,8 +35,9 @@ const DEFAULT_OPTIONS = {
33
35
*
34
36
* @template VMValue - コンポーネントインスタンスの型。コンポーネントのプロパティやメソッドへの型安全なアクセスを提供します
35
37
* @param component - テスト対象のVueコンポーネント
36
- * @param testingPinia - テスト用のPiniaインスタンス(bindTestingPinia関数で作成したもの)
37
38
* @param options - マウントオプション(任意)
39
+ * @param options.testingPinia - テスト用のPiniaインスタンス(bindTestingPinia関数で作成したもの)
40
+ * @param options.attachTo - コンポーネントをマウントするDOM要素
38
41
* @param options.props - コンポーネントに渡すprops
39
42
* @param options.slots - コンポーネントのスロット
40
43
* @param options.shallow - 浅いレンダリングを行うかどうか
@@ -49,8 +52,9 @@ const DEFAULT_OPTIONS = {
49
52
* const useUserStore = pinia.stores.user;
50
53
* useUserStore.user = { name: 'Test User' };
51
54
*
52
- * const wrapper = await mountSuspendedComponent<{ computedProperty: string }>(MyComponent, pinia, {
53
- * props: { message: 'Hello' }
55
+ * const wrapper = await mountSuspendedComponent<{ computedProperty: string }>(MyComponent, {
56
+ * testingPinia: pinia
57
+ * props: { message: 'Hello' },
54
58
* });
55
59
*
56
60
* // コンポーネントの検証
@@ -63,11 +67,10 @@ const DEFAULT_OPTIONS = {
63
67
*/
64
68
export async function mountSuspendedComponent < VMValue > (
65
69
component : Component ,
66
- testingPinia : ReturnType < typeof bindTestingPinia > ,
67
70
options : Partial < MountOptions > = DEFAULT_OPTIONS ,
68
71
) : Promise < VueWrapper < ComponentPublicInstance & VMValue > > {
69
72
const mergedOptions = { ...DEFAULT_OPTIONS , ...options } ;
70
- const { attachTo, props, slots, shallow, stubs, mocks, options : additionalOptions } = mergedOptions ;
73
+ const { testingPinia , attachTo, props, slots, shallow, stubs, mocks, options : additionalOptions } = mergedOptions ;
71
74
72
75
return await mountSuspended ( component , {
73
76
...additionalOptions ,
@@ -76,7 +79,7 @@ export async function mountSuspendedComponent<VMValue>(
76
79
slots,
77
80
shallow,
78
81
global : {
79
- plugins : [ testingPinia ] ,
82
+ plugins : testingPinia ? [ testingPinia ] : [ ] ,
80
83
stubs : {
81
84
...DEFAULT_STUBS ,
82
85
...stubs ,
0 commit comments