1

When using jasmine-node (or any other JavaScript node.js testing framework come to think of it) to unit test node.js applications is it necessary to use the pattern:

//file-under-test.js
exports.some_func_of_many = function () {...};


//jasmine_node-spec.js
var functions_to_test = require("file-under-test");
.....
some jasmine tests here

i.e. does everything I need/want to test need to be exposed via the module object? It seems to me that I probably don't want to be exporting all the code in my modules...or am I missing some other pattern or something important?

1 Answer 1

1

Yes, you will need to export everything you want to test directly. A common patten is to preface "private" methods with an underscore to give consumers of your modules a hint of what they should be using while still exposing it for testing purposes.

That said, there is a school of thought that says you should only export (and test) your publicly consumable methods, and let those tests "cover" your internal methods.

Sign up to request clarification or add additional context in comments.

1 Comment

Cheers, Thanks for the speedy answer, coming from Java and pretty new to javascript, some things are quite different.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.