-
-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add throwOnNotFound method #225
Open
jacobsmith-fusionalliance
wants to merge
9
commits into
thlorenz:master
Choose a base branch
from
jacobsmith-fusionalliance:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+65
−0
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f1d871f
Add throwOnUnresolvedImports method
jacobsmith-fusionalliance fcc9d1c
Update throwOnUnresolvedImports to just throwOnUnresolved and update …
jacobsmith-fusionalliance a41e995
update name to throwOnNotFound
jacobsmith-fusionalliance a424158
remove package-lock.json
jacobsmith-fusionalliance 3a79f3d
update Readme with information on throwOnNotFound
jacobsmith-fusionalliance f7d6ea4
update Readme with information on throwOnNotFound
jacobsmith-fusionalliance 663d8ba
bump for github
jacobsmith-fusionalliance e75e3fe
Merge branch 'master' of github.com:jacobsmith-fusionalliance/proxyquire
jacobsmith-fusionalliance 4add017
Update README.md
bendrucker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,41 @@ Two simple steps to override require in your tests: | |
- therefore specify it exactly as in the require statement inside the tested file | ||
- values themselves are key/value pairs of functions/properties and the appropriate override | ||
|
||
## Throw if proxyquire tries to load a stub that does not exist | ||
|
||
By default `proxyquire` will stub out modulePaths, whatever their path may be. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid "stub out," it's unclear what that means. It's also not true, as the sentence is written. |
||
This includes if a dependency is not accessible (wrong file path) or not installed and accessible. | ||
|
||
To raise an error if `proxyquire` attempts to load a module that does not exist, | ||
you can utilize the *throwOnNotFound* function. | ||
|
||
**Without throwOnNotFound:** | ||
```javascript | ||
proxyquire('./foo', { | ||
'doesNotExist': () => {} | ||
}); | ||
``` | ||
|
||
The above code snippet will not raise any errors. | ||
|
||
**With throwOnNotFound:** | ||
```javascript | ||
var proxyquireThrowOnNotFound = require('proxyquire').throwOnNotFound(); | ||
|
||
proxyquireThrowOnNotFound('./foo', { | ||
'doesNotExist': () => {} | ||
}); | ||
``` | ||
|
||
This will throw an error when your tests run letting you know that proxyquire | ||
cannot find `doesNotExist`. Typically, this is occurs when a file was renamed | ||
in the calling module but was not updated in the proxyquire definition in the | ||
test. | ||
|
||
This method is also chainable with the *callThru* methods: | ||
|
||
`var proxyquireThrowOnNotFoundAndNoCallThru = proxyquire.throwOnNotFound().noCallThru()` | ||
|
||
## Preventing call thru to original dependency | ||
|
||
By default proxyquire calls the function defined on the *original* dependency whenever it is not found on the stub. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not line-wrap Markdown