cleishm / jsmockito

Javascript mocking framework inspired by the awesome mockito
http://jsmockito.org
Other
106 stars 19 forks source link

JsMockito with NodeJS #7

Open luciferous opened 13 years ago

luciferous commented 13 years ago

Hi Chris, great work with JsMockito. I'm using it in a browser and NodeJS environment. It's unclear to me if there is a roadmap for getting JsMockito to work with NodeJS, but I thought I'd contribute my half-solution so other people looking to do the same may build on top of it.

The details are in https://gist.github.com/1227705.

cleishm commented 13 years ago

There is no particular roadmap. It's pretty usable as is, but enhancement's are always good.

I'm not sure exactly what this patch you've sent does: the diff isn't overly explanatory. If you'd like to contribute a change, please fork the repository on github, add your changes (making sure you write appropriate test cases) and then send a pull request with the detail.

cheers, chris

On 20 September 2011 00:00, Neuman Vong < reply@reply.github.com>wrote:

Hi Chris, great work with JsMockito. I'm using it in a browser and NodeJS environment. It's unclear to me if there is a roadmap for getting JsMockito to work with NodeJS, but I thought I'd contribute my half-solution so other people looking to do the same may build on top of it.

The details are in https://gist.github.com/1227705.

Reply to this email directly or view it on GitHub: https://github.com/chrisleishman/jsmockito/issues/7

jefflage commented 12 years ago

chris,

i just spent some time getting jsmockito plugged into nodejs, specifically into a vows test, and i now understand what luciferous did, at least with the exports.

Both JSMockito and JSHamcrest have support for copying public functions into a target context, but the issue is that they don't export anything by default. In Node, you use require() to get access to another module. The object returned by require is effective the public API for the module you required. That object can get it's members in a number of different ways, but the basic issue is that it has to have something. Given that JSMockito don't export anything by default, you can't get a handle to anything that would allow you to run the import JSMockito.Integration.importTo() function.

So to work with Node JSMockito has to export something, thus the addition of the line: JsMockito.Integration.importTo( exports );

Does this help? -Jeff