1
1
import { useQuery } from '@tanstack/react-query' ;
2
- import { matchPath , useLocation } from 'react-router-dom' ;
2
+ import { useMatch } from 'react-router-dom' ;
3
3
import { camelCaseObject } from '@edx/frontend-platform' ;
4
4
import { when } from 'jest-when' ;
5
5
@@ -12,7 +12,7 @@ import { useORAConfig, usePageData } from './api';
12
12
13
13
jest . mock ( '@tanstack/react-query' , ( ) => ( { useQuery : jest . fn ( ) } ) ) ;
14
14
15
- jest . mock ( 'react-router-dom' , ( ) => ( { matchPath : jest . fn ( ) , useLocation : jest . fn ( ) } ) ) ;
15
+ jest . mock ( 'react-router-dom' , ( ) => ( { useMatch : jest . fn ( ) } ) ) ;
16
16
17
17
interface QueryFn { ( ) : string }
18
18
interface QueryArgs { queryKey : string , queryFn : QueryFn }
@@ -86,23 +86,16 @@ describe('lms api hooks', () => {
86
86
. mockImplementationOnce ( mockUseQuery ( data ) ) ;
87
87
} ;
88
88
89
- const mockMatchPath = ( path ) => {
90
- when ( matchPath )
91
- . calledWith ( { path } , path )
89
+ const mockUseMatch = ( path ) => {
90
+ when ( useMatch )
91
+ . calledWith ( path )
92
92
. mockReturnValueOnce ( { pattern : { path } } ) ;
93
93
} ;
94
94
95
- const mockUseLocation = ( path ) => {
96
- when ( useLocation )
97
- . calledWith ( )
98
- . mockReturnValueOnce ( { pathname : path } ) ;
99
- } ;
100
-
101
95
const testUsePageData = usePageData as unknown as MockPageDataUseConfigHook ;
102
96
describe ( 'submission' , ( ) => {
103
97
beforeEach ( ( ) => {
104
- mockMatchPath ( routes . submission ) ;
105
- mockUseLocation ( routes . submission ) ;
98
+ mockUseMatch ( routes . submission ) ;
106
99
mockUseQueryForPageData ( fakeData . pageData . shapes . emptySubmission , false ) ;
107
100
out = testUsePageData ( ) ;
108
101
} ) ;
@@ -119,8 +112,7 @@ describe('lms api hooks', () => {
119
112
} ) ;
120
113
describe ( 'assessment' , ( ) => {
121
114
beforeEach ( ( ) => {
122
- mockMatchPath ( routes . peerAssessment ) ;
123
- mockUseLocation ( routes . peerAssessment ) ;
115
+ mockUseMatch ( routes . peerAssessment ) ;
124
116
mockUseQueryForPageData ( fakeData . pageData . shapes . peerAssessment , true ) ;
125
117
out = testUsePageData ( ) ;
126
118
} ) ;
@@ -136,8 +128,7 @@ describe('lms api hooks', () => {
136
128
} ) ;
137
129
} ) ;
138
130
it ( 'returns empty object from data if data has not been returned' , ( ) => {
139
- mockMatchPath ( routes . submission ) ;
140
- mockUseLocation ( routes . submission ) ;
131
+ mockUseMatch ( routes . submission ) ;
141
132
mockUseQueryForPageData ( undefined , false ) ;
142
133
out = testUsePageData ( ) ;
143
134
expect ( out . data ) . toEqual ( { } ) ;
0 commit comments