Skip to content

Commit

Permalink
test: Add test case for composition API
Browse files Browse the repository at this point in the history
closes #185
  • Loading branch information
winniehell committed May 8, 2023
1 parent e62b3f5 commit 61842cc
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions tests/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ const { Store } = require('../src')
const Helper = require('./Helper')
const { mount } = require('@vue/test-utils')
const Vue = require('vue')
const { mapState } = require('vuex')
const { mapState, useStore } = require('vuex')

const isVue3 = Vue.version.startsWith('3.')
const onlyVue3 = isVue3 ? it : it.skip

/**
* @param {{ store: Store }} options
*/
function vue2CompatibleMocks ({ store }) {
const mocks = { $store: store }
if (Vue.version < '3') {
if (!isVue3) {
return { mocks }
}

Expand Down Expand Up @@ -140,4 +143,30 @@ describe('Store Mock', () => {
}).toThrow(/module "nonExistent" not defined in state/)
})
})

onlyVue3('supports composition API', () => {
const wrapper = mount(
{
setup () {
const store = useStore()
return {
composition: Vue.computed(() => store.state.composition),
}
},
render: () => null,
},
{
global: {
provide: {
store: new Store({
state: {
composition: 'api',
},
}),
},
},
},
)
expect(wrapper.vm.composition).toBe('api')
})
})

0 comments on commit 61842cc

Please sign in to comment.