Question

I'm trying to use Nodeunit to test my Backbone models and later I'd like to test the other components as well. The main reason I'm using Nodeunit is because my server tests are using it already and I'd like to stick with one testing framework.

Is this a good idea? I've made one feable attempt of setting up a unit test, but it fails when I try to require the underscore and backbone libraries:

Error: Cannot find module 'underscore'

Is it possible at all to use nodeunit for this and if not what would the recommend unit-testing framework be for testing a Backbone app?

Était-ce utile?

La solution

You are probably not including your RequireJS config in your NodeUnit test runner html. Or, if you are, perhaps NodeUnit isn't serving dynamic content in the same way. I've not used it before, but I ran into a similar problem with Jasmine.

With the jasmine approach, I had to do something like this:

# coffeescript #
TEST_ENV = (typeof window['jasmine'] == 'object')
prefix = if TEST_ENV then '/public' else ''
baseUrl = prefix + '/javascripts'

In the jasmine-gem world (within rails), the /public folder is served out of the actual /public route. (Normal rails serving assumes the /public folder is actually the root route.) So, this bit of code checks for a test context and adds the /public prefix to the baseUrl. Then, in my requireJS config, I assign this baseUrl.

This may be the same issue you are having with NodeUnit.

For more information on how I set this up, as well as special RequireJS + Jasmine integration, see my blog post.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top