Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/composables/useExternalLink.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { computed } from 'vue'

import { electronAPI, isElectron } from '@/utils/envUtil'

Check failure on line 3 in src/composables/useExternalLink.ts

View workflow job for this annotation

GitHub Actions / test

tests-ui/tests/composables/useExternalLink.test.ts

Error: [vitest] There was an error when mocking a module. If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/vi.html#vi-mock ❯ src/composables/useExternalLink.ts:3:31 Caused by: Caused by: ReferenceError: Cannot access 'mockLocale' before initialization ❯ tests-ui/tests/composables/useExternalLink.test.ts:17:15 ❯ src/composables/useExternalLink.ts:3:31
import { useI18n } from 'vue-i18n'
import { i18n } from '@/i18n'

/**
* Composable for building docs.comfy.org URLs with automatic locale and platform detection
Expand All @@ -23,7 +23,7 @@
* ```
*/
export function useExternalLink() {
const { locale } = useI18n()
const locale = computed(() => String(i18n.global.locale.value))

const isChinese = computed(() => {
return locale.value === 'zh' || locale.value === 'zh-TW'
Expand Down
12 changes: 7 additions & 5 deletions tests-ui/tests/composables/useExternalLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ vi.mock('@/utils/envUtil', () => ({
electronAPI: vi.fn()
}))

// Mock vue-i18n
// Mock global i18n locale ref
const mockLocale = ref('en')
vi.mock('vue-i18n', () => ({
useI18n: vi.fn(() => ({
locale: mockLocale
}))
vi.mock('@/i18n', () => ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to just createI18n as a plugin for the test

i18n: {
global: {
locale: mockLocale
}
}
}))

// Import after mocking to get the mocked versions
Expand Down
Loading