Closed LoiKos closed 5 years ago
but then that is not how rewrite use to work. I was trying to migrate from rewrite to this plugin and keeps getting the same error for set or get
I figure out my problem sorry i forgot to explain and close this.
I Run into this issue cause i wasn't using any function i would to retrieve in an exported function. To get the plugin work you need to add an exported function, or object,or .... that use or references at least function you want to test.
Then they will appear in the hide variable : RewireAPI
For example :
the following will not work
//myfunction.js
const funct1 = () => {}
export const funct2 = () => {}
//myfunction.test.js
import { funct2, __RewireAPI__ as FuncAPI } from './myfunction'
// FuncAPI will be null
this will work
//myfunction.js
const funct1 = () => {}
export const funct2 = () => {
funct1()
}
//myfunction.test.js
import { funct2, __RewireAPI__ as FuncAPI } from './myfunction'
const funct = FuncAPI.__get__('funct1') // will receive the functions as expected
That doesn't seem right. This does not work. For me, RewireAPI is still empty.
@LoiKos Thanks! It works! @cjancsar Did you use none exported functions in exported functions? RewireAPI contains only these.
Hello,
I create this issue because i wanted to test unexported functions from a module and it take me a few times to understand the process. I'm not quite sure what is the expected behavior of the plugin so i can't tell if it's a real bug or a limitation.
I use cjs and jest for my test.
container.mjs
and my test file container.spec.mjs :
and when running this test, i get the following :
At this point i don't understand why it doesn't work but i tried to add the following in container.mjs :
And it works ! So if i understand well that mean you need all functions to be used or exported to be testable ? But during development you can need to test them before using. Am i missing somethings ?