Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

mockery and Jasmine #26

Open
cristiingineru opened this issue Feb 3, 2015 · 5 comments
Open

mockery and Jasmine #26

cristiingineru opened this issue Feb 3, 2015 · 5 comments
Labels

Comments

@cristiingineru
Copy link

Maybe it's worth mentioning in the readme or wiki that when used with Jasmine mockery needs to be enclosed in a define () and the 'module' should be received as an argument.

The var m = require('module') is simply not working. Maybe it's a Jasmine issue or an undocumented expected behavior.

define(['module'], function (m) {
//var m = require('module') // this call fails even after enclosing it in a define(['module']) {}
.
.
.
return { ... };
}
@davglass
Copy link
Collaborator

davglass commented Feb 3, 2015

I've never used Jasmine so I'll have to look into how it works in order to figure out what is breaking.

Do you have a simple repro case that I can run to test with? I can add that to our new tests to make sure that it's executed when we build.

@davglass davglass added the bug label Feb 3, 2015
@cristiingineru
Copy link
Author

I believe the issue is not Jasmine, but RequireJS. Here is an example that includes the change I made in mockery.js at the beginning of the file:
https://github.com/cristiingineru/testingWithMocks/blob/master/js/node_modules/mockery/mockery.js

After this small change the mockery.js module loads correctly (it's not throwing). But the original modules are not replaced with mocks during testing. Here is an example:
https://github.com/cristiingineru/testingWithMocks/blob/master/js/specs/cSpec.js

Maybe it's just something wrong with my setup.

@davidnorth
Copy link

Its not working for me with Jasmine, hookedLoader is never called for any require following mockery.enable(). I'm not using RequireJS. I added a console.log to check if hookedLoader was called. I tested just in the REPL and it was working fine.

@3den
Copy link

3den commented Apr 2, 2015

I am using mockery with jasmine and it is working fine. But I using it with the wrapper posted on #28

@3den
Copy link

3den commented Apr 2, 2015

when you mock paths you need use exactly the same string that was used to require, it not the path from your tests file.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants