@putout/plugin-convert-mock-require-to-mock-import
🐊Putout plugin adds ability to convert mockRequire to mockImport
Last updated 2 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @putout/plugin-convert-mock-require-to-mock-import 
SYNC missed versions from official npm registry.

@putout/plugin-convert-mock-require-to-mock-import NPM version

????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

Current Tags

  • 4.1.1                                ...           latest (2 years ago)

9 Versions

  • 4.1.1                                ...           2 years ago
  • 4.1.0                                ...           4 years ago
  • 4.0.0                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (0)
None
Dev Dependencies (7)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |