Skip to content

Instantly share code, notes, and snippets.

@nilswloka
Last active October 4, 2016 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilswloka/0edde20fd2587fe22ed3920715b4f0ee to your computer and use it in GitHub Desktop.
Save nilswloka/0edde20fd2587fe22ed3920715b4f0ee to your computer and use it in GitHub Desktop.
Use proxyquire to deal with platform specific extensions when writing test for React Native code
import TheModule from 'platform-specific-module';
export default class ComponentUnderTest extends Component {
render() {
return (
<TheModule />
)
}
}
import proxyquire from 'proxyquire';
import platformSpecificModule from 'platform-specific-module/index.ios'; // or whichever version you prefer
const SubjectUnderTest = proxyquire.noCallThru().load('./index', {
'platform-specific-module': {
'TheModule': platformSpecificModule
}
}).default
@thlorenz
Copy link

thlorenz commented Oct 4, 2016

This only works cause your imports are converted to commonJS requires BTW.
If/once node.js supports import natively then proxyquire won't work this way anymore .. just a heads up and maybe you should stick with require anyhow for now ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment