{"repo":"jhnns/rewire","free":true,"listed":false,"github":"https://github.com/jhnns/rewire","clone":"git clone https://github.com/jhnns/rewire.git","description":"Easy monkey-patching for node.js unit tests","language":"JavaScript","stars":3093,"topics":["mock","testing","unit-testing","monkey-patching"],"license":"MIT","category":"dev-tools","readme_excerpt":"rewire ====== Easy monkey-patching for node.js unit tests rewire adds a special setter and getter to modules so you can modify their behaviour for better unit testing. You may - inject mocks for other modules or globals like process - inspect private variables - override variables within the module. Please note: The current version of rewire is only compatible with CommonJS modules. See Limitations. Installation ------------ npm install rewire Introduction ------------ Imagine you want to test this module: Now within your test module: rewire acts exactly like require. With just one difference: Your module will now export a special setter and getter for private variables. This allows you to mock everything in the top-level scope of the module, like the fs module for example. Just pass the variable name as first parameter and your mock as second. You can also set multiple variables with one call. You may also override globals. These changes are only within the module, so you don't have to be concerned that other modules are influenced by your mock. set returns a function which reverts the changes introduced by this particular set call For your convenience you can also use the with method which reverts the given changes after it finished. The with method is also aware of promises. If a thenable is returned all changes stay until the promise has either been resolved or rejected. Limitations ----------- Babel's ES module emulation During the transpilation step from ESM to CJS modu","default_branch":null,"files":null,"tree":[],"storefront":"/r/jhnns","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/jhnns/rewire/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."}