-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
f1d871f
fcc9d1c
a41e995
a424158
3a79f3d
f7d6ea4
663d8ba
e75e3fe
4add017
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -63,4 +63,18 @@ describe('Illegal parameters to resolve give meaningful errors', function () { | |||||
throws(act, /Invalid stub: "myStub" cannot be undefined/) | ||||||
}) | ||||||
}) | ||||||
|
||||||
describe('when I pass a stub with a key that is not required on the proxyquired object', function () { | ||||||
function act () { | ||||||
const proxyquireThrowOnUnresolved = proxyquire.throwOnUnresolved() | ||||||
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.
Suggested change
The return value is the main fn itself—assigning the return value implies a new copy of proxyquire which isn't the case here. This test mutates state it doesn't own and I'd rather that be apparent in case it causes future issues. 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. Ah yes, thanks for pointing that out! I've been using a generator function most of the time around proxyquire to have a "clean slate" for each test run so forgot it was actually mutating here! |
||||||
|
||||||
proxyquireThrowOnUnresolved('./samples/foo', { | ||||||
nonExistent: () => {} | ||||||
}) | ||||||
} | ||||||
|
||||||
it('throws an exception with the stub key', function () { | ||||||
throws(act, /Cannot find module 'nonExistent'/) | ||||||
}) | ||||||
}) | ||||||
}) |
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.
throwOnNotFound
is the best I can come up with. Handling unresolved stubs is more of a description of how proxyquire works as opposed to what the user wants.