Skip to content

Commit f8fd0c8

Browse files
committed
test: add failing tests
1 parent ef7b29c commit f8fd0c8

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

Diff for: packages/pinia/__tests__/multipleRoots.spec.ts

+32-18
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,75 @@ describe('Multiple Roots', () => {
1111
})
1212
}
1313

14-
it('uses the same root in child components by default', () => {
14+
it('provides a pinia to children components', async () => {
1515
const pinia = createPinia()
16-
const useStore = defineMyStore()
16+
const useA = defineMyStore()
17+
let nestedA!: ReturnType<typeof useA>
1718

1819
const ChildComponent = defineComponent({
1920
template: 'no',
2021
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)
2326
},
2427
})
25-
2628
mount(
2729
{
2830
template: '<ChildComponent />',
2931
components: { ChildComponent },
3032
setup() {
31-
const store = useStore()
33+
providePinia(createPinia())
34+
const store = useA()
3235
expect(store.n).toBe(0)
3336
store.n++
3437
},
3538
},
3639
{ global: { plugins: [pinia] } }
3740
)
3841

39-
const store = useStore()
42+
const store = useA()
43+
// should be the parent one
44+
expect(store).not.toBe(nestedA)
4045
expect(store.n).toBe(1)
4146
})
4247

43-
it('can use a new pinia root for all child components', async () => {
48+
it('should be able to use plugins', async () => {
4449
const pinia = createPinia()
45-
const useStore = defineMyStore()
50+
const useA = defineMyStore()
51+
52+
// @ts-expect-error: type not defined
53+
pinia.use(() => ({ parent: true }))
4654

4755
const ChildComponent = defineComponent({
4856
template: 'no',
4957
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)
5264
},
5365
})
5466
mount(
5567
{
5668
template: '<ChildComponent />',
5769
components: { ChildComponent },
5870
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)
6380
},
6481
},
6582
{ global: { plugins: [pinia] } }
6683
)
67-
68-
const store = useStore()
69-
expect(store.n).toBe(0)
7084
})
7185
})

0 commit comments

Comments
 (0)