1- import { describe , it , expect , vi , beforeEach } from 'vitest' ;
2- import { renderHook , act } from '@testing-library/react' ;
3- import { useInstrumentVisualization } from '../useInstrumentVisualization' ;
41import { toBasicISOString } from '@douglasneuroinformatics/libjs' ;
2+ import { act , renderHook } from '@testing-library/react' ;
3+ import { beforeEach , describe , expect , it , vi } from 'vitest' ;
4+
5+ import { useInstrumentVisualization } from '../useInstrumentVisualization' ;
56
67const mockUseInstrument = vi . hoisted ( ( ) =>
78 vi . fn ( ( ) => ( {
@@ -27,9 +28,9 @@ const FIXED_TEST_DATE = new Date('2025-04-30T12:00:00Z');
2728const mockInstrumentRecords = {
2829 data : [
2930 {
30- date : FIXED_TEST_DATE ,
3131 computedMeasures : { } ,
32- data : { someValue : 'abc' }
32+ data : { someValue : 'abc' } ,
33+ date : FIXED_TEST_DATE
3334 }
3435 ]
3536} ;
@@ -68,8 +69,7 @@ describe('useInstrumentVisualization', () => {
6869 act ( ( ) => result . current . dl ( 'CSV' ) ) ;
6970 expect ( records ) . toBeDefined ( ) ;
7071 expect ( mockDownloadFn ) . toHaveBeenCalledTimes ( 1 ) ;
71-
72- const [ filename , getContentFn ] = mockDownloadFn . mock . calls [ 0 ] ;
72+ const [ filename , getContentFn ] = mockDownloadFn . mock . calls [ 0 ] ?? [ ] ;
7373 expect ( filename ) . toContain ( '.csv' ) ;
7474 const csvContents = getContentFn ( ) ;
7575 expect ( csvContents ) . toMatch ( `subjectId,Date,someValue\r\ntestId,${ toBasicISOString ( FIXED_TEST_DATE ) } ,abc` ) ;
@@ -82,8 +82,7 @@ describe('useInstrumentVisualization', () => {
8282 act ( ( ) => dl ( 'TSV' ) ) ;
8383 expect ( records ) . toBeDefined ( ) ;
8484 expect ( mockDownloadFn ) . toHaveBeenCalledTimes ( 1 ) ;
85-
86- const [ filename , getContentFn ] = mockDownloadFn . mock . calls [ 0 ] ;
85+ const [ filename , getContentFn ] = mockDownloadFn . mock . calls [ 0 ] ?? [ ] ;
8786 expect ( filename ) . toContain ( '.tsv' ) ;
8887 const tsvContents = getContentFn ( ) ;
8988 expect ( tsvContents ) . toMatch ( `subjectId\tDate\tsomeValue\r\ntestId\t${ toBasicISOString ( FIXED_TEST_DATE ) } \tabc` ) ;
@@ -97,7 +96,7 @@ describe('useInstrumentVisualization', () => {
9796 expect ( records ) . toBeDefined ( ) ;
9897 expect ( mockDownloadFn ) . toHaveBeenCalledTimes ( 1 ) ;
9998
100- const [ filename , getContentFn ] = mockDownloadFn . mock . calls [ 0 ] ;
99+ const [ filename , getContentFn ] = mockDownloadFn . mock . calls [ 0 ] ?? [ ] ;
101100 expect ( filename ) . toContain ( '.csv' ) ;
102101 const csvLongContents = getContentFn ( ) ;
103102 expect ( csvLongContents ) . toMatch (
@@ -113,7 +112,7 @@ describe('useInstrumentVisualization', () => {
113112 expect ( records ) . toBeDefined ( ) ;
114113 expect ( mockDownloadFn ) . toHaveBeenCalledTimes ( 1 ) ;
115114
116- const [ filename , getContentFn ] = mockDownloadFn . mock . calls [ 0 ] ;
115+ const [ filename , getContentFn ] = mockDownloadFn . mock . calls [ 0 ] ?? [ ] ;
117116 expect ( filename ) . toMatch ( '.tsv' ) ;
118117 const tsvLongContents = getContentFn ( ) ;
119118 expect ( tsvLongContents ) . toMatch (
@@ -129,7 +128,7 @@ describe('useInstrumentVisualization', () => {
129128 expect ( records ) . toBeDefined ( ) ;
130129 expect ( mockDownloadFn ) . toHaveBeenCalledTimes ( 1 ) ;
131130
132- const [ filename , getContentFn ] = mockDownloadFn . mock . calls [ 0 ] ;
131+ const [ filename , getContentFn ] = mockDownloadFn . mock . calls [ 0 ] ?? [ ] ;
133132 expect ( filename ) . toMatch ( '.json' ) ;
134133 const jsonContents = await getContentFn ( ) ;
135134 expect ( jsonContents ) . toContain ( '"someValue": "abc"' ) ;
0 commit comments