From f8d06c250bc0a91849e858657fcdff1e87ac2b30 Mon Sep 17 00:00:00 2001 From: Laura Martinez Garcia Date: Tue, 30 Jan 2024 09:48:03 +0100 Subject: [PATCH] chore(test): pr comments --- .../tagging/store/__tests__/actions.spec.ts | 10 +++++----- .../__tests__/session.service.spec.ts | 20 +++++++------------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/packages/x-components/src/x-modules/tagging/store/__tests__/actions.spec.ts b/packages/x-components/src/x-modules/tagging/store/__tests__/actions.spec.ts index 80f65c95b6..79692bef86 100644 --- a/packages/x-components/src/x-modules/tagging/store/__tests__/actions.spec.ts +++ b/packages/x-components/src/x-modules/tagging/store/__tests__/actions.spec.ts @@ -16,13 +16,13 @@ describe('testing tagging module actions', () => { localVue.config.productionTip = false; // Silent production console messages. localVue.use(Vuex); - const mockedSessionId = 'beabb84c-c0aa-4d3a-911b-54779f7f4a8f'; - const selfSpy = jest.spyOn(self, 'self', 'get'); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore + const selfSpy = jest.spyOn(self, 'self', 'get') as jest.SpyInstance<{ + crypto: { randomUUID: () => string }; + }>; + selfSpy.mockImplementation(() => ({ crypto: { - randomUUID: () => mockedSessionId + randomUUID: () => Math.floor(Math.random() * 1000000000).toString() } })); diff --git a/packages/x-utils/src/services/__tests__/session.service.spec.ts b/packages/x-utils/src/services/__tests__/session.service.spec.ts index b9fa8bfc23..ae7c455d0d 100644 --- a/packages/x-utils/src/services/__tests__/session.service.spec.ts +++ b/packages/x-utils/src/services/__tests__/session.service.spec.ts @@ -5,13 +5,14 @@ describe('testing session id service', () => { const mockedStorageService = new InMemoryStorageService(); const sessionService = new DefaultSessionService(mockedStorageService, 1); const storageKey = DefaultSessionService.SESSION_ID_KEY; - const mockedSessionId = 'beabb84c-c0aa-4d3a-911b-54779f7f4a8f'; - const selfSpy = jest.spyOn(self, 'self', 'get'); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore + + const selfSpy = jest.spyOn(self, 'self', 'get') as jest.SpyInstance<{ + crypto: { randomUUID: () => string }; + }>; + selfSpy.mockImplementation(() => ({ crypto: { - randomUUID: () => mockedSessionId + randomUUID: () => Math.floor(Math.random() * 1000000000).toString() } })); @@ -51,14 +52,7 @@ describe('testing session id service', () => { jest.advanceTimersByTime(999); const session2 = sessionService.getSessionId(); expect(session1).toEqual(session2); - jest.advanceTimersByTime(1001); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - selfSpy.mockImplementation(() => ({ - crypto: { - randomUUID: () => 'beabb84c-c0aa-4d3a-552n-54779f7f4a8f' - } - })); + jest.advanceTimersByTime(1000); const session3 = sessionService.getSessionId(); expect(session1).not.toEqual(session3); });