I have been trying to integrate unit testing with my Backbone models through an express node.js project, and having difficulties grasping exactly how to accomplish this task. (sidenote: I come from a lot of Java background, and I realize there are differences, but I am loving the simplicity and elegance of the node development environment so far.)
My problem stems from the following issue, backbone models need to be exposed to the browser in order to run within it, whereas testing through mocha is "server side" on the node runtime environment.
Here is an example of what I am talking about:
Model File: /public/js/backbone/models.js
var SomeModel = Backbone.Model.extend({...});
Server Side Test: /test/backbone/models-test.js
???
I write ??? because normal unit testing via server side you just do:
var SomeModule = require('./someModule');
and go about your merry way. Obviously, since the browser is not running within Node, modules aren't readily available.
I have read some posts stating you need to wrap your browser-side javascript within require.js which will put those javascript files into the node namespace automagically allowing you to do a require and go on with your testing. However, I have not found a coherent way of accomplishing such a task, and I have tried searching around for examples, but can't seem to find something that applies. Granted, it very well might be my general lack of knowledge for this framework since I'm still wrapping my head around the entire idea of how things are scoped in javascript, injection of dependencies, etc.
Any help would be much appreciated, and I apologize if this question has been asked a million times already, I'm sure it has, and I'm asking it in an incorrect way.
Thanks in advance.