@@ -365,6 +365,34 @@ test('ESM mocking with namedExports option', async (t) => {
365365 } ) ;
366366} ) ;
367367
368+ test ( 'JSON mocking' , async ( t ) => {
369+ await t . test ( 'with defaultExport' , async ( t ) => {
370+ const fixturePath = fixtures . path ( 'module-mocking' , 'basic.json' ) ;
371+ const fixture = pathToFileURL ( fixturePath ) ;
372+ const { default : original } = await import ( fixture , { with : { type : 'json' } } ) ;
373+
374+ assert . deepStrictEqual ( original , { foo : 'bar' } ) ;
375+
376+ const defaultExport = { qux : 'zed' } ;
377+
378+ t . mock . module ( fixture , { defaultExport } ) ;
379+
380+ const { default : mocked } = await import ( fixture , { with : { type : 'json' } } ) ;
381+
382+ assert . deepStrictEqual ( mocked , defaultExport ) ;
383+ } ) ;
384+
385+ await t . test ( 'throws without appropriate import attributes' , async ( t ) => {
386+ const fixturePath = fixtures . path ( 'module-mocking' , 'basic.json' ) ;
387+ const fixture = pathToFileURL ( fixturePath ) ;
388+
389+ const defaultExport = { qux : 'zed' } ;
390+ t . mock . module ( fixture , { defaultExport } ) ;
391+
392+ await assert . rejects ( ( ) => import ( fixture ) , / i m p o r t a t t r i b u t e / ) ;
393+ } ) ;
394+ } ) ;
395+
368396test ( 'modules cannot be mocked multiple times at once' , async ( t ) => {
369397 await t . test ( 'CJS' , async ( t ) => {
370398 const fixture = fixtures . path ( 'module-mocking' , 'basic-cjs.js' ) ;
0 commit comments