Skip to content

Commit

Permalink
Merge 8683af3 into 534ddbb
Browse files Browse the repository at this point in the history
  • Loading branch information
kobbikobb committed Jun 22, 2019
2 parents 534ddbb + 8683af3 commit c6efe7b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/_howto/stub-dependency.md
@@ -0,0 +1,21 @@
---
layout: page
title: How to stub a dependency of a module?
---

To stub dependency(imported module) of a module under test you have to import it explicitly in your test and stub the desired method.

## Example

```javascript
import * as importedModule from "./importedModule";
import {getTheSecret} from "./moduleUnderTest";

"test should get secret": function () {
sinon.stub(importedModule, "getSecretNumber").returns(3);

const result = getTheSecret();

assert(result).toBe('The secret was: 3');
}
```
2 changes: 2 additions & 0 deletions docs/_releases/latest/stubs.md
Expand Up @@ -76,6 +76,8 @@ Replaces `object.method` with a stub function. An exception is thrown if the pro

The original function can be restored by calling `object.method.restore();` (or `stub.restore();`).

A dependency of a module can be stubbed [see example](../../_howto/stub-dependency.md).

#### ~~`var stub = sinon.stub(object, "method", func);`~~

This has been removed from `v3.0.0`. Instead you should use
Expand Down

0 comments on commit c6efe7b

Please sign in to comment.