@@ -11,61 +11,75 @@ describe('Multiple Roots', () => {
11
11
} )
12
12
}
13
13
14
- it ( 'uses the same root in child components by default' , ( ) => {
14
+ it ( 'provides a pinia to children components' , async ( ) => {
15
15
const pinia = createPinia ( )
16
- const useStore = defineMyStore ( )
16
+ const useA = defineMyStore ( )
17
+ let nestedA ! : ReturnType < typeof useA >
17
18
18
19
const ChildComponent = defineComponent ( {
19
20
template : 'no' ,
20
21
setup ( ) {
21
- const store = useStore ( )
22
- expect ( store . n ) . toBe ( 1 )
22
+ // should use the provided pinia by the parent
23
+ const store = useA ( )
24
+ nestedA = store
25
+ expect ( store . n ) . toBe ( 0 )
23
26
} ,
24
27
} )
25
-
26
28
mount (
27
29
{
28
30
template : '<ChildComponent />' ,
29
31
components : { ChildComponent } ,
30
32
setup ( ) {
31
- const store = useStore ( )
33
+ providePinia ( createPinia ( ) )
34
+ const store = useA ( )
32
35
expect ( store . n ) . toBe ( 0 )
33
36
store . n ++
34
37
} ,
35
38
} ,
36
39
{ global : { plugins : [ pinia ] } }
37
40
)
38
41
39
- const store = useStore ( )
42
+ const store = useA ( )
43
+ // should be the parent one
44
+ expect ( store ) . not . toBe ( nestedA )
40
45
expect ( store . n ) . toBe ( 1 )
41
46
} )
42
47
43
- it ( 'can use a new pinia root for all child components ' , async ( ) => {
48
+ it ( 'should be able to use plugins ' , async ( ) => {
44
49
const pinia = createPinia ( )
45
- const useStore = defineMyStore ( )
50
+ const useA = defineMyStore ( )
51
+
52
+ // @ts -expect-error: type not defined
53
+ pinia . use ( ( ) => ( { parent : true } ) )
46
54
47
55
const ChildComponent = defineComponent ( {
48
56
template : 'no' ,
49
57
setup ( ) {
50
- const store = useStore ( )
51
- expect ( store . n ) . toBe ( 0 )
58
+ // should use the provided pinia by the parent
59
+ const store = useA ( )
60
+ // @ts -expect-error: not defined
61
+ expect ( store . parent ) . toBeUndefined ( )
62
+ // @ts -expect-error: not defined
63
+ expect ( store . child ) . toBe ( true )
52
64
} ,
53
65
} )
54
66
mount (
55
67
{
56
68
template : '<ChildComponent />' ,
57
69
components : { ChildComponent } ,
58
70
setup ( ) {
59
- providePinia ( createPinia ( ) )
60
- const store = useStore ( )
61
- expect ( store . n ) . toBe ( 0 )
62
- store . n ++
71
+ const pinia = createPinia ( )
72
+ // @ts -expect-error: type not defined
73
+ pinia . use ( ( ) => ( { child : true } ) )
74
+ providePinia ( pinia )
75
+ const store = useA ( )
76
+ // @ts -expect-error: not defined
77
+ expect ( store . child ) . toBeUndefined ( )
78
+ // @ts -expect-error: not defined
79
+ expect ( store . parent ) . toBe ( true )
63
80
} ,
64
81
} ,
65
82
{ global : { plugins : [ pinia ] } }
66
83
)
67
-
68
- const store = useStore ( )
69
- expect ( store . n ) . toBe ( 0 )
70
84
} )
71
85
} )
0 commit comments