Skip to content
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

Jest support for td replace #338

Merged
merged 10 commits into from
Feb 11, 2018
Merged

Jest support for td replace #338

merged 10 commits into from
Feb 11, 2018

Conversation

searls
Copy link
Member

@searls searls commented Feb 11, 2018

Add awareness of testdouble-jest to td.replace

If a user calls td.replace for a module from a jest test, it will
delegate to a new jest-specific module faker. If testdouble-jest is
not initialized (as detected by an absence of `td.mock`), then the
lib will complain, to hopefully make folks aware of testdouble-jest
in the first place.

When td.mock is detected, it will just translate the `td.replace`
contract, which actually returns the fake. This should be more portable.

There are a few warts, namely that I can't figure out how to resolve a
path, so I have to attempt to require manually stubbed items in a
try-catch (sort of defeating the purpose of a stub override) to know
whether to flip Jest's virtual bit or not. (If the dep is real and
virtual is set to true, the real dep apparently wins)

Fixes #337

If a user calls td.replace for a module from a jest test, it will
delegate to a new jest-specific module faker. If testdouble-jest is
not initialized (as detected by an absence of `td.mock`), then the
lib will complain, to hopefully make folks aware of testdouble-jest
in the first place. 

When td.mock is detected, it will just translate the `td.replace` 
contract, which actually returns the fake. This should be more portable.

There are a few warts, namely that I can't figure out how to resolve a
path, so I have to attempt to require manually stubbed items in a 
try-catch (sort of defeating the purpose of a stub override) to know
whether to flip Jest's virtual bit or not. (If the dep is real and 
virtual is set to true, the real dep apparently wins)
By explicitly using npm link we should iron out npm issues
Zero idea what this is but after an hour I'm ready to blame npm for it
@searls searls merged commit 2026eeb into master Feb 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn jest users when they call td.replace(moduleName) and point them to testdouble-jest
1 participant