Skip to content

Commit

Permalink
feat(jest): 100% coverage for store/settings/actions
Browse files Browse the repository at this point in the history
  • Loading branch information
drepram committed Apr 25, 2022
1 parent ab2e092 commit 3e65c13
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions store/settings/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,6 @@ describe('actions.default', () => {
}
})

test('setConsentScan with consentScan but error occured', async () => {
const commit = jest.fn()

try {
await actions.default.setConsentScan({ commit }, true)
} catch (error) {
expect(commit).toHaveBeenCalledWith('setConsentScan', true)
expect(error).toBeInstanceOf(Error)
expect(error).toHaveProperty(
'message',
TextileError.USERINFO_MANAGER_NOT_FOUND,
)
}
})

test('setConsentScan with consentScan', async () => {
Vue.prototype.$TextileManager = new TextileManager()
const TMConstructor = Vue.prototype.$TextileManager
Expand All @@ -77,4 +62,37 @@ describe('actions.default', () => {
expect(commit).toHaveBeenCalledWith('setConsentScan', true)
expect(TMConstructor.userInfoManager.setConsent).toHaveBeenCalled()
})

test('setConsentScan with consentScan but error occured', async () => {
Vue.prototype.$TextileManager = new TextileManager()
const commit = jest.fn()

jest.spyOn(console, 'log').mockImplementation()
await actions.default.setConsentScan({ commit }, true)
expect(console.log).toHaveBeenCalled()
})

test('setBlockNsfw with blockNsfw', async () => {
Vue.prototype.$TextileManager = new TextileManager()
const TMConstructor = Vue.prototype.$TextileManager
TMConstructor.userInfoManager = jest.fn()
TMConstructor.userInfoManager.setBlockNsfw = jest
.fn()
.mockReturnValueOnce(Promise.resolve())

const commit = jest.fn()

await actions.default.setBlockNsfw({ commit }, true)
expect(TMConstructor.userInfoManager.setBlockNsfw).toHaveBeenCalled()
expect(commit).toHaveBeenCalledWith('setBlockNsfw', true)
})

test('setBlockNsfw with blockNsfw but error occured', async () => {
Vue.prototype.$TextileManager = new TextileManager()
const commit = jest.fn()

jest.spyOn(console, 'log').mockImplementation()
await actions.default.setBlockNsfw({ commit }, true)
expect(console.log).toHaveBeenCalled()
})
})

0 comments on commit 3e65c13

Please sign in to comment.