esmock
(c)Bumblehead
This package must be used with node's experimental --loader,
ava --node-arguments="--loader=esmock"
mocha --loader=esmock
Add the command to your package.json,
{
"name": "my-module",
"type": "module",
"scripts" : {
"unit-test": "ava --node-arguments=\"--loader=esmock\""
}
}
And use it
import test from 'ava';
import esmock from 'esmock';
test('should mock module and local file at the same time', async t => {
const main = await esmock('./local/main.js', {
'astringifierpackage' : o => JSON.stringify(o),
'./local/util.js' : {
exportedFunction : () => 'foobar'
}
});
t.is(main(), 'foobar, ' + JSON.stringify({ test: 'object' }));
});
changelog
- 0.1.0 Apr.10.2021
- adds support for native es modules