@@ -1041,75 +1041,72 @@ export function testDefineLoader<Context = void>(
10411041 expect ( data . value ) . toEqual ( 'ok,one' )
10421042 } )
10431043
1044- it . todo (
1045- `reuses a nested loader result even if it's called first from another loader` ,
1046- async ( ) => {
1047- const l1 = mockedLoader ( { key : 'search-results' , lazy : false } )
1048- const spy = vi . fn ( async ( to : RouteLocationNormalizedLoaded ) => {
1049- // get search results from the search loader
1050- const data = await l1 . loader ( )
1051- // then fetch images in high res
1052- return `${ data } ,${ to . query . p } `
1053- } )
1054- const l2 = loaderFactory ( {
1055- fn : spy ,
1056- key : 'images-from-search' ,
1044+ it ( `reuses a nested loader result even if it's called first from another loader` , async ( ) => {
1045+ const l1 = mockedLoader ( { key : 'search-results' , lazy : false } )
1046+ const spy = vi . fn ( async ( to : RouteLocationNormalizedLoaded ) => {
1047+ // get search results from the search loader
1048+ const data = await l1 . loader ( )
1049+ // then fetch images in high res
1050+ return `${ data } ,${ to . query . p } `
1051+ } )
1052+ const l2 = loaderFactory ( {
1053+ fn : spy ,
1054+ key : 'images-from-search' ,
10571055
1058- // to ensure this is not awaited
1059- lazy : true ,
1060- server : false ,
1061- } )
1056+ // to ensure this is not awaited
1057+ lazy : true ,
1058+ server : false ,
1059+ } )
10621060
1063- let useDataResult ! : ReturnType < typeof l1 . loader >
1061+ let useDataResult ! : ReturnType < typeof l1 . loader >
10641062
1065- const component = defineComponent ( {
1066- setup ( ) {
1067- // it shouldn't matter if l2 is used or not, what matters is the order
1068- useDataResult = l1 . loader ( )
1069- l2 ( )
1070- return { }
1071- } ,
1072- template : `<p>a</p>` ,
1073- } )
1074- const router = getRouter ( )
1075- router . addRoute ( {
1076- name : '_test' ,
1077- path : '/fetch' ,
1078- meta : {
1079- // the images should run first to simulate the issue
1080- // in practice the user does not control the order of the loaders and it shouldn't matter
1081- loaders : [ l2 , l1 . loader ] ,
1082- // this scenario would work
1083- // loaders: [l1.loader, l2],
1084- } ,
1085- component,
1086- } )
1063+ const component = defineComponent ( {
1064+ setup ( ) {
1065+ // it shouldn't matter if l2 is used or not, what matters is the order
1066+ useDataResult = l1 . loader ( )
1067+ l2 ( )
1068+ return { }
1069+ } ,
1070+ template : `<p>a</p>` ,
1071+ } )
1072+ const router = getRouter ( )
1073+ router . addRoute ( {
1074+ name : '_test' ,
1075+ path : '/fetch' ,
1076+ meta : {
1077+ // the images should run first to simulate the issue
1078+ // in practice the user does not control the order of the loaders and it shouldn't matter
1079+ loaders : [ l2 , l1 . loader ] ,
1080+ // this scenario would work
1081+ // loaders: [l1.loader, l2],
1082+ } ,
1083+ component,
1084+ } )
10871085
1088- const wrapper = mount ( RouterViewMock , {
1089- global : {
1090- plugins : [
1091- [ DataLoaderPlugin , { router } ] ,
1092- ...( plugins ?.( customContext ! ) || [ ] ) ,
1093- ] ,
1094- } ,
1095- } )
1086+ const wrapper = mount ( RouterViewMock , {
1087+ global : {
1088+ plugins : [
1089+ [ DataLoaderPlugin , { router } ] ,
1090+ ...( plugins ?.( customContext ! ) || [ ] ) ,
1091+ ] ,
1092+ } ,
1093+ } )
10961094
1097- router . push ( '/fetch?p=one' )
1098- await vi . runOnlyPendingTimersAsync ( )
1099- l1 . resolve ( 'search' )
1100- await flushPromises ( )
1095+ router . push ( '/fetch?p=one' )
1096+ await vi . runOnlyPendingTimersAsync ( )
1097+ l1 . resolve ( 'search' )
1098+ await flushPromises ( )
11011099
1102- const app : App = wrapper . vm . $ . appContext . app
1103- const l2Data = app . runWithContext ( ( ) => l2 ( ) )
1100+ const app : App = wrapper . vm . $ . appContext . app
1101+ const l2Data = app . runWithContext ( ( ) => l2 ( ) )
11041102
1105- expect ( useDataResult ?. data . value ) . toEqual ( 'search' )
1106- expect ( l2Data . data . value ) . toEqual ( 'search,one' )
1107- // FIXME: go from here: figure out why with colada it's called 2 times
1108- // but only once with the basic loader. Probably need a currentLoad variable
1109- expect ( l1 . spy ) . toHaveBeenCalledTimes ( 1 )
1110- expect ( spy ) . toHaveBeenCalledTimes ( 1 )
1111- }
1112- )
1103+ expect ( useDataResult ?. data . value ) . toEqual ( 'search' )
1104+ expect ( l2Data . data . value ) . toEqual ( 'search,one' )
1105+ // FIXME: go from here: figure out why with colada it's called 2 times
1106+ // but only once with the basic loader. Probably need a currentLoad variable
1107+ expect ( l1 . spy ) . toHaveBeenCalledTimes ( 1 )
1108+ expect ( spy ) . toHaveBeenCalledTimes ( 1 )
1109+ } )
11131110
11141111 it . todo ( 'passes to and from to the function version of lazy' , async ( ) => { } )
11151112 it . todo ( 'can be first non-lazy then lazy' , async ( ) => { } )
0 commit comments