Search code examples
node.jsrequirejsjasmine-node

How to run jasmine-node tests with RequireJS


How can I properly run jasmine tests using jasmine-node and RequireJS?

I already tried something like this, but doesnt work (CoffeeScript):

requirejs = require 'requirejs'
requirejs.config { baseUrl: __dirname + '/../' }

requirejs ['MyClasses', 'FooClass'], (MyClasses, FooClass) ->

  describe "someProp", ->
    it "should be true", ->
      expect(MyClasses.FooClass.someProp).toEqual true

Finished in 0 seconds 0 tests, 0 assertions, 0 failures

My goal is to write modular classes using RequireJS, CoffeeScript and classes must be testable with jasmine-node (CI server).

How can I do that please? Thank you!

EDIT:

I executing tests with command (at directory with tests):

jasmine-node ./

Solution

  • It seems that jasmine-node and require.js are completely incompatible. That said, it is possible to run jasmine tests on require.js modules in node using a bit of extra code. Take a look at https://github.com/geddski/amd-testing to see how.