https://github.com/danvk/stub-require
Automatically create stubbed-out versions of node.js modules, ala Jest's autoMock
https://github.com/danvk/stub-require
Last synced: about 1 year ago
JSON representation
Automatically create stubbed-out versions of node.js modules, ala Jest's autoMock
- Host: GitHub
- URL: https://github.com/danvk/stub-require
- Owner: danvk
- License: apache-2.0
- Created: 2014-10-27T21:34:51.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-10-28T03:14:48.000Z (over 11 years ago)
- Last Synced: 2025-01-16T10:03:44.206Z (over 1 year ago)
- Language: JavaScript
- Size: 148 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
stub-require
===========
Automatically create stubbed-out versions of node.js modules, ala Jest's autoMock.
Usage:
```javascript
// BigComplexModule.js
module.exports = {
foo: function() { return 42; }
};
```
```javascript
// foo.js
module.exports = function() {
return require('./BigComplexModule').foo();
};
```
```javascript
// foo-test.js
var stubRequire = require('stubrequire')(['BigComplexModule']),
foo = stubRequire('./foo');
foo(); // returns undefined, not 42.
```
stubrequire will mock out both methods and classes, i.e. if a module exports
`module.foo`, then `new module.foo()` will return an object with the same
methods as the original, but all stubbed out.
Installation
```
npm install --save-dev stub-require
```