From 3e65c13286a7a1e16b0936e1446aa8d5e399167a Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Mon, 25 Apr 2022 14:19:22 +0700 Subject: [PATCH] feat(jest): 100% coverage for store/settings/actions --- store/settings/actions.test.ts | 48 +++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/store/settings/actions.test.ts b/store/settings/actions.test.ts index 4680a09b4c..68bbf602cb 100644 --- a/store/settings/actions.test.ts +++ b/store/settings/actions.test.ts @@ -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 @@ -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() + }) })