I\'m trying to figure out on how to test internal (i.e. not exported) functions in nodejs (preferably with mocha or jasmine). And i have no idea!
Let say I have a mo
Essentially you need to merge the source context with the test cases - one way to do this would be using a small helper function wrapping the tests.
demo.js
const internalVar = 1;
demo.test.js
const importing = (sourceFile, tests) => eval(`${require('fs').readFileSync(sourceFile)};(${String(tests)})();`);
importing('./demo.js', () => {
it('should have context access', () => {
expect(internalVar).toBe(1);
});
});