@@ -5,18 +5,24 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
55
66import { useInstrumentVisualization } from '../useInstrumentVisualization' ;
77
8- const mockInstrument = {
9- useInstrument : vi . fn ( ( ) => ( {
10- instrument : {
11- internal : {
12- name : 'test'
13- }
8+ const mockUseInstrument = vi . hoisted ( ( ) =>
9+ vi . fn ( ( ) => ( {
10+ internal : {
11+ name : 'test'
1412 }
1513 } ) )
16- } ;
14+ ) ;
15+
16+ const mockRecords = [
17+ {
18+ __date__ : new Date ( ) . getDate ( ) ,
19+ __time__ : new Date ( ) . getTime ( ) ,
20+ someValue : 'abc'
21+ }
22+ ] ;
1723
1824vi . mock ( '@/hooks/useInstrument' , ( ) => ( {
19- useInstrument : ( ) => mockInstrument
25+ useInstrument : mockUseInstrument
2026} ) ) ;
2127
2228const mockStore = {
@@ -27,9 +33,9 @@ const mockStore = {
2733 }
2834 } ) )
2935} ;
30- const mockDownload = {
31- useDownload : vi . fn ( )
32- } ;
36+
37+ const mockUseDownload = vi . fn ( ) ;
38+
3339const mockNotification = {
3440 useNotificationsStore : vi . fn ( )
3541} ;
@@ -50,7 +56,7 @@ vi.mock('@/store', () => ({
5056} ) ) ;
5157
5258vi . mock ( '@douglasneuroinformatics/libui/hooks' , ( ) => ( {
53- useDownload : ( ) => mockDownload ,
59+ useDownload : ( ) => mockUseDownload ,
5460 useNotificationsStore : ( ) => mockNotification ,
5561 useTranslation : ( ) => mockTranslation
5662} ) ) ;
@@ -61,14 +67,7 @@ vi.mock('react', async (importOriginal) => {
6167 ...actual ,
6268 useEffect : vi . fn ( ) ,
6369 useMemo : vi . fn ( ) ,
64- useState : vi . fn ( ( ) => [
65- 'mockedRecords' ,
66- vi . fn ( ( ) => ( {
67- __date__ : new Date ( ) . getDate ( ) ,
68- __time__ : new Date ( ) . getTime ( ) ,
69- someValue : 'abc'
70- } ) )
71- ] )
70+ useState : vi . fn ( ( ) => [ mockRecords , 'setRecords' ] )
7271 } ;
7372} ) ;
7473
@@ -92,8 +91,6 @@ describe('useInstrumentVisualization tests', () => {
9291 params : { subjectId : 'testId' }
9392 } ) ;
9493 act ( ( ) => dl ( 'CSV' ) ) ;
95- expect ( mockInstrument . useInstrument ) . toHaveBeenCalledOnce ( ) ;
96- expect ( mockStore . useAppStore ) . toHaveBeenCalled ( ) ;
9794 expect ( records ) . toBeDefined ( ) ;
9895 } ) ;
9996 } ) ;
0 commit comments