@putout/plugin-convert-mock-require-to-mock-import
v4.1.1
Published
šPutout plugin adds ability to convert mockRequire to mockImport
Downloads
43,147
Maintainers
Readme
@putout/plugin-convert-mock-require-to-mock-import
šPutout plugin adds ability to convert mockRequire to mockImport. Moved to @putout/plugin-tape
.
Install
npm i @putout/plugin-convert-mock-require-to-mock-import -D
Rule
Rule convert-mock-require-to-mock-import
is enabled by default for *.mjs
, to disable add to .putout.json
:
Good complement of @putout/plugin-tape
{
"rules": {
"convert-mock-require-to-mock-import": "off"
}
}
ā Example of incorrect code
const mockRequire = require('mock-require');
const {reRequire, stopAll} = mockRequire;
test('', (t) => {
mockRequire('fs/promises', {
unlink: stub(),
});
const fn = reRequire('..');
fn();
stopAll();
t.end();
});
ā Example of correct code
import {createMockImport} from 'mock-import';
const {
mockImport,
reImport,
stopAll,
} = createMockImport(import.meta.url);
test('', async (t) => {
mockImport('fs/promises', {
unlink: stub(),
});
const fn = await reImport('..');
fn();
stopAll();
t.end();
});
License
MIT