{"repo":"theKashey/rewiremock","free":true,"listed":false,"github":"https://github.com/theKashey/rewiremock","clone":"git clone https://github.com/theKashey/rewiremock.git","description":"The right way to mock dependencies in Node.js or webpack environment.","language":"JavaScript","stars":513,"topics":["mock","proxyquire","webpack","dependency-injection","nodejs","mockery","magic","mock-library"],"license":"MIT","category":"dev-tools","readme_excerpt":"Quick start 1. Install - yarn add --dev rewiremock or npm i --save-dev rewiremock 2. Setup I would recommend not importing rewiremock directly from tests, but create a rewiremock.js file and require it - in this way, you can preconfigure rewiremock for all tests. for ts/es6/esm use import for commonjs/nodejs use require('rewiremock/node') for webpack You will also need to add a few plugins to your webpack test configuration (no need to keep them all in production). If you import rewiremock directly from your tests, you dont need overrideEntryPoint 3. Use There are 3 ways to mock, all with pros and cons. proxyquire - like Simplest one. 💡to make it really \"proxyquire like\" - add .relative plugin. Which will allow mocking of direct dependencies only, like with proxyquire mockery - like Most powerfull one jest - like Shortest one 💡 requires rewiremock/babel plugin 4. Tune There are plenty of plugins to make your life easier. For example - this is my favorite setup What command to use???!!! There are two important things here: - You can use require or import to specify the file to require and the file to mock. This helps to resolve file names and maintain type information(if you have it). See Guided Mocking below. - You can mix simplified helpers (like .proxy ) and the main API. ESM modules If you want to support ESM modules(powered by @std/ESM, not native modules) you have to use the import function. - use .module - an \"async\" version of .proxy - or just use import - that would","default_branch":null,"files":null,"tree":[],"storefront":"/r/theKashey","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/theKashey/rewiremock/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}