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

Mocking/stubbing dependencies in tests #52

Closed
tomatau opened this issue Apr 13, 2015 · 4 comments
Closed

Mocking/stubbing dependencies in tests #52

tomatau opened this issue Apr 13, 2015 · 4 comments

Comments

@tomatau
Copy link

tomatau commented Apr 13, 2015

I'm in the midst of a battle trying to support babel imports for niceness but also be able to stub out dependencies in tests.

Right now the only solution I can find that doesn't throw a giant wobbly in my webpack bundle is to use the inject-loader when importing files from tests. However - this only works with require syntax.

Are there any recommendations for stubbing out dependencies that are imported using babel-loader? Preferably having the only requirements being isolated to the test files themselves.

@Couto
Copy link
Member

Couto commented Apr 14, 2015

I can imagine a lot of ways (and probably most of them wrong) out of the blue.
Can you provide a small test case so that we can see your setup? :)

@revolunet
Copy link

I do it like this in my spec file:

var MyModule = require('inject?moduleToMock!./MyModule')({'moduleToMock': myMock})

@tomatau
Copy link
Author

tomatau commented Apr 27, 2015

Using the inject loader doesn't work for me in combination with with babel and mocha loaders.

Right now I'm using sinon after importing and making sure my modules all export objects.

@revolunet
Copy link

ok strange, jasmine here.

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

No branches or pull requests

4 participants