Skip to content

Commit

Permalink
test: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Feb 18, 2022
1 parent 591bfaf commit 7c3066b
Showing 1 changed file with 6 additions and 33 deletions.
39 changes: 6 additions & 33 deletions packages/pinia/__tests__/multipleRoots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import { defineComponent } from 'vue'

describe('Multiple Roots', () => {
function defineMyStore() {
return defineStore({
id: 'main',
return defineStore('main', {
state: () => ({
n: 0,
}),
})
}

it('uses the same root in child components by default', () => {
expect.assertions(2)
const pinia = createPinia()
const useStore = defineMyStore()

Expand All @@ -37,10 +35,12 @@ describe('Multiple Roots', () => {
},
{ global: { plugins: [pinia] } }
)

const store = useStore()
expect(store.n).toBe(1)
})

it('can use a new pinia root for all child components', async () => {
expect.assertions(2)
const pinia = createPinia()
const useStore = defineMyStore()

Expand All @@ -64,35 +64,8 @@ describe('Multiple Roots', () => {
},
{ global: { plugins: [pinia] } }
)
})

it('state is shared between child components', async () => {
expect.assertions(3)
const pinia = createPinia()
const useStore = defineMyStore()

const ChildComponent = defineComponent({
template: 'no',
props: { counter: { type: Number, required: true } },
setup(props: { counter: number }) {
const store = useStore()
expect(store.n).toBe(props.counter)
store.n++
},
})
mount(
{
template:
'<ChildComponent :counter="0" /><ChildComponent :counter="1" />',
components: { ChildComponent },
setup() {
const store = useStore()
expect(store.n).toBe(0)
store.n++
providePinia(createPinia())
},
},
{ global: { plugins: [pinia] } }
)
const store = useStore()
expect(store.n).toBe(0)
})
})

0 comments on commit 7c3066b

Please sign in to comment.