Skip to content

Commit

Permalink
feat: allow additional stubs to be passed (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Aug 16, 2019
1 parent 6dc2089 commit 81e3a76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ const myClient = http2spy.require(require.resolve("./lib/my-client"));
assert.strictEqual(http2spy.requests[0][":method"], 'GET');
```

## Passing Additional Stubs

http2spy is just a thin wrapper on top of
[proxyquire](https://www.npmjs.com/package/proxyquire), if you would like to
pass additional libraries to stub, simply provide them as a second parameter:

```js
const myClient = http2spy.require(require.resolve("./lib/my-client"), {
'second-library': {
foo: () => {}
}
});
```

## License

Apache Version 2.0
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
get requests() {
return requests;
},
require: modulePath => {
require: (modulePath, additionalStubs = {}) => {
const stubs = {
http2: {
connect: (target, connectionOptions) => {
Expand All @@ -21,6 +21,6 @@ module.exports = {
"@global": true
}
};
return proxyquire(modulePath, stubs);
return proxyquire(modulePath, Object.assign(additionalStubs, stubs));
}
};

0 comments on commit 81e3a76

Please sign in to comment.