Skip to content

Commit

Permalink
chore(tests): Add GitHub Actions for Vue 2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
winniehell committed May 2, 2023
1 parent 2db3c7a commit 770b4f2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/vue-2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on:
- pull_request
- push

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: yarn
- run: yarn install --frozen-lockfile
- run: yarn add --dev vue@2 vuex@3 @vue/test-utils@1
- run: yarn test
- uses: codecov/codecov-action@v3
18 changes: 15 additions & 3 deletions tests/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@
const { Store } = require('../src')
const Helper = require('./Helper')
const { mount } = require('@vue/test-utils')
const Vue = require('vue')
const { mapState } = require('vuex')

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

return { global: { mocks } }
}

describe('Store Mock', () => {
it('work with no args', () => {
expect(() => {
Expand Down Expand Up @@ -70,11 +83,10 @@ describe('Store Mock', () => {
'module/nested/mmGetter': 3,
},
})
const mocks = { $store: store }
/** @type {import('@vue/test-utils').Wrapper} */
let wrapper
beforeEach(() => {
wrapper = mount(Helper, { global: { mocks } })
wrapper = mount(Helper, vue2CompatibleMocks({ store }))
})

it('correctly maps state', () => {
Expand Down Expand Up @@ -120,7 +132,7 @@ describe('Store Mock', () => {
render: () => null,
computed: mapState('nonExistent', ['a']),
},
{ global: { mocks } },
vue2CompatibleMocks({ store }),
)
expect(() => {
// eslint-disable-next-line no-unused-expressions
Expand Down

0 comments on commit 770b4f2

Please sign in to comment.