Skip to content

Commit

Permalink
feat(jest): 100% coverage for store/files/actions.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
drepram committed Feb 16, 2022
1 parent 1a82310 commit ec2fa2b
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions store/files/actions.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,56 @@
import * as actions from '~/store/files/actions'
import { DataStateType } from '~/store/dataState/types'

describe('actions.default.handler', () => {
test('0', () => {
const result: any = actions.default.handler()
expect(result).toMatchSnapshot()
})
})
describe('actions.default.fetchFiles', () => {
test('file state empty', async () => {
const commit = jest.fn()
const rootState: any = {
dataState: {
files: DataStateType.Empty,
},
}

await actions.default.fetchFiles({ commit, rootState })

expect(commit).toHaveBeenCalledWith(
'dataState/setDataState',
{ key: 'files', value: DataStateType.Loading },
{ root: true },
)
})
test('file state loading', async () => {
const commit = jest.fn()
const rootState: any = {
dataState: {
files: DataStateType.Loading,
},
}

await actions.default.fetchFiles({ commit, rootState })

expect(commit).not.toHaveBeenCalled()
})
test('file state ready', async () => {
// In order to trigger the last condition (else), we cannot use ones that have been covered (Empty, Loading, Updating); hence we used Ready for the DataStateType.
const commit = jest.fn()
const rootState: any = {
dataState: {
files: DataStateType.Ready,
},
}

await actions.default.fetchFiles({ commit, rootState })

expect(commit).toHaveBeenCalledWith(
'dataState/setDataState',
{ key: 'files', value: DataStateType.Updating },
{ root: true },
)
})
})

0 comments on commit ec2fa2b

Please sign in to comment.