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

JsMockito polluting global space with JsHamcrest #35

Open
fcuenca opened this issue Mar 23, 2015 · 0 comments
Open

JsMockito polluting global space with JsHamcrest #35

fcuenca opened this issue Mar 23, 2015 · 0 comments

Comments

@fcuenca
Copy link

fcuenca commented Mar 23, 2015

I installed jsmockito and jshamcrest as separate npm packages, and I found that jshamcrest matchers weren't working when verifying mocks. Matchers were working perfectly fine in other assertions, however.

After some debugging, I figured that the problem was that I had two conflicting versions of jshamcrest: v0.7, which I installed, and v0.6.7, which jsmockito installs as dependency. When jsmockito first loads, it creates a global JsHamcrest variable which points to it's private version of JsHamcrest (0.6.7). When my code later requires jshamcrest, the newer version is loaded, so when I refer to matchers, they are from a different library than that jsmockito is using, and therefore the objects are not recognized as matchers, and not used.

I solved the problem creating a small utility module that loads both libraries and replaces the global library:

     var jshamcrest = require('jshamcrest').JsHamcrest;
     var jsmockito = require("jsmockito").JsMockito;

    global.JsHamcrest = jshamcrest;

    jsmockito.Integration.importTo(global);

Perhaps the jsmockito module could avoid polluting the global namespace, or relax the version number declared for the dependency (currently set to match exactly 0.6.7)

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

1 participant