You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am trying to use quibble to mock an ESM module and its subdependencies on a really simple exemple, but I seem to be missing something or encountering unexpected behavior.
Here's my setup:
// src/subdep.mjsconsole.log('Load src/subdep.mjs');exportfunctionmyFunction(){return"real subdep function is called...";}// src/utils.mjsconsole.log('Load src/utils.mjs');import{myFunction}from'./subDep.mjs'exportfunctionfetchData(){constres=myFunction();return`real utils.fetchData function is called with subdep : ${res}`;}// ___test__/test.mjsimportquibblefrom'quibble'awaitquibble.esm('../src/subdep.mjs',{myFunction:()=>{return'mocked subdep ! Yeah !'}},{mocked : 'replacement universe'});constsubdep=awaitimport('../src/subdep.mjs');console.log(subdep.myFunction());// OK => mocked subdep ! Yeah !console.log('-------------------');constsubject=awaitimport('../src/utils.mjs');constresult=subject.fetchData()console.log(result);// FAIL => real subdep function is called...
Command and Output :(node version = v22.4.1)
node __test__/test.mjs
Actual Output :
mocked subdep ! Yeah !
-------------------
Load src/subdep.mjs <--- I did not expect that
Load src/utils.mjs
real utils.fetchData function is called with subdep : real subdep function is called... <--- make sence but not expected
Expected Output :
mocked subdep ! Yeah !
-------------------
Load src/utils.mjs
real utils.fetchData function is called with subdep : mocked subdep ! Yeah !
Questions :
Is this the expected behavior, or am I missing something in how quibble works with ESM modules and subdependencies?
If this is a limitation, are there workarounds or other strategies to mock ESM subdependencies in this context?
The text was updated successfully, but these errors were encountered:
Yoshyn
changed the title
Question : How to make mock work with ESM and subdependencies ?
Question : Mock a subdependencies with ESM. Is it the expected behaviour ?
Nov 21, 2024
Hi, I am trying to use
quibble
to mock an ESM module and its subdependencies on a really simple exemple, but I seem to be missing something or encountering unexpected behavior.Here's my setup:
Command and Output : (node version = v22.4.1)
Actual Output :
Expected Output :
Questions :
The text was updated successfully, but these errors were encountered: