Skip to content

Commit 1671d72

Browse files
committed
fix: test code
1 parent 04617dd commit 1671d72

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import { useMissingNodes } from '@/workbench/extensions/manager/composables/node
99
import { useWorkflowPacks } from '@/workbench/extensions/manager/composables/nodePack/useWorkflowPacks'
1010
import { useComfyManagerStore } from '@/workbench/extensions/manager/stores/comfyManagerStore'
1111

12-
// Mock Vue's onMounted to execute immediately for testing
13-
vi.mock('vue', async () => {
14-
const actual = await vi.importActual<typeof import('vue')>('vue')
12+
vi.mock('@vueuse/core', async () => {
13+
const actual =
14+
await vi.importActual<typeof import('@vueuse/core')>('@vueuse/core')
1515
return {
1616
...actual,
17-
onMounted: (cb: () => void) => cb()
17+
createSharedComposable: (fn: any) => fn
1818
}
1919
})
2020

@@ -34,6 +34,12 @@ vi.mock('@/stores/nodeDefStore', () => ({
3434
useNodeDefStore: vi.fn()
3535
}))
3636

37+
vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({
38+
useWorkflowStore: vi.fn(() => ({
39+
activeWorkflow: null
40+
}))
41+
}))
42+
3743
vi.mock('@/scripts/app', () => ({
3844
app: {
3945
graph: {
@@ -176,13 +182,13 @@ describe('useMissingNodes', () => {
176182
})
177183

178184
describe('automatic data fetching', () => {
179-
it('fetches workflow packs automatically when none exist', async () => {
185+
it('fetches workflow packs automatically on initialization via watch with immediate:true', async () => {
180186
useMissingNodes()
181187

182188
expect(mockStartFetchWorkflowPacks).toHaveBeenCalledOnce()
183189
})
184190

185-
it('does not fetch when packs already exist', async () => {
191+
it('fetches even when packs already exist (watch always fires with immediate:true)', async () => {
186192
mockUseWorkflowPacks.mockReturnValue({
187193
workflowPacks: ref(mockWorkflowPacks),
188194
isLoading: ref(false),
@@ -194,10 +200,10 @@ describe('useMissingNodes', () => {
194200

195201
useMissingNodes()
196202

197-
expect(mockStartFetchWorkflowPacks).not.toHaveBeenCalled()
203+
expect(mockStartFetchWorkflowPacks).toHaveBeenCalledOnce()
198204
})
199205

200-
it('does not fetch when already loading', async () => {
206+
it('fetches even when already loading (watch fires regardless of loading state)', async () => {
201207
mockUseWorkflowPacks.mockReturnValue({
202208
workflowPacks: ref([]),
203209
isLoading: ref(true),
@@ -209,7 +215,7 @@ describe('useMissingNodes', () => {
209215

210216
useMissingNodes()
211217

212-
expect(mockStartFetchWorkflowPacks).not.toHaveBeenCalled()
218+
expect(mockStartFetchWorkflowPacks).toHaveBeenCalledOnce()
213219
})
214220
})
215221

0 commit comments

Comments
 (0)