function startMocking(path, mockExport) {
var calledFrom = callerId.getData().filePath;
if (typeof mockExport === 'string') {
mockExport = getFullPath(mockExport, calledFrom);
}
pendingMockExports[getFullPath(path, calledFrom)] = mockExport;
}n/a
function reRequire(path) {
var module = getFullPath(path, callerId.getData().filePath);
delete require.cache[require.resolve(module)];
return require(module);
}...
var fs2 = require('fs');
var path2 = require('path');
fs1 === fs2; // false
path1 === path2; // false
```
### `mock.reRequire(path)`
__path__: `String`
The file whose cache you want to refresh. This is useful if you're trying to mock a dependency for a file that has already
been required elsewhere (possibly in another test file). Normally, Node.js will cache this file, so any mocks that you apply afterwards
will have no effect. `reRequire` clears the cache and allows your mock to work.
```javascript
var fs = require('fs');
...function stopMocking(path) {
var calledFrom = callerId.getData().filePath;
var fullPath = getFullPath(path, calledFrom);
delete pendingMockExports[fullPath];
delete mockExports[fullPath];
}...
`test/b_spec.js`:
```javascript
var mock = require('mock-require');
mock('../some/other/dependency', './spy');
...
```
### `mock.stop(path)`
__path__: `String`
The module you that you want to stop mocking. This is the same string you would pass in if you wanted to `require` the module.
This will only modify variables used after `mock.stop` is called. For example:
...function stopMockingAll() {
mockExports = {};
pendingMockExports = {};
}...
mock.stop('fs');
var fs2 = require('fs');
fs1 === fs2; // false
```
### `mock.stopAll()`
This function can be used to remove all registered mocks without the need to remove them individually using `mock.stop()`.
```javascript
mock('fs', {});
mock('path', {});
...