diff --git a/src/components/Location.test.ts b/src/components/Location.test.ts index 1f3a8567..09932d2c 100644 --- a/src/components/Location.test.ts +++ b/src/components/Location.test.ts @@ -2,26 +2,30 @@ import { mount } from '@vue/test-utils'; import { NCollapseItem } from 'naive-ui'; import Location from '@/components/Location.vue'; -import useListProxies from '@/composables/useListProxies'; + +jest.mock('@/composables/useActiveTab', () => ({ + __esModule: true, + default: jest.fn(() => ({ + activeTabHost: 'example.com', + })), +})); jest.mock('@/composables/useListProxies', () => ({ __esModule: true, - default: jest.fn(), + default: jest.fn(() => ({ + proxiesList: [ + { + country: 'Albania', + }, + { + country: 'Australia', + }, + ], + })), })); describe('Location', () => { it('should show two countries', async () => { - (useListProxies as jest.Mock).mockReturnValueOnce({ - proxiesList: [ - { - country: 'Albania', - }, - { - country: 'Australia', - }, - ], - }); - const wrapper = mount(Location); await wrapper.vm.$nextTick(); diff --git a/src/composables/useActiveTab.ts b/src/composables/useActiveTab.ts index 3f2c5f83..87b5bf38 100644 --- a/src/composables/useActiveTab.ts +++ b/src/composables/useActiveTab.ts @@ -4,16 +4,12 @@ const activeTabHost = ref(''); const isAboutPage = ref(false); const getActiveTab = async () => { - try { - const activeWindow = await browser.windows.getCurrent({ populate: true }); - const activeTab = activeWindow.tabs!.find((tab) => tab.active); + const activeWindow = await browser.windows.getCurrent({ populate: true }); + const activeTab = activeWindow.tabs!.find((tab) => tab.active); - const activeTabURL = new URL(activeTab!.url!); - activeTabHost.value = activeTabURL.hostname; - isAboutPage.value = activeTabURL.protocol === 'about:'; - } catch (error) { - console.log('No active tab found'); - } + const activeTabURL = new URL(activeTab!.url!); + activeTabHost.value = activeTabURL.hostname; + isAboutPage.value = activeTabURL.protocol === 'about:'; }; const useActiveTab = () => {