Reputation: 4911
I'm using Coffeescript for everything, and have ran into trouble trying to include chai.js
into my test.
my configs/testacular.conf.js
looks like this (note the relative basePath
):
basePath = '../';
// Install devDependencies with `npm install` first before attempting to run Testacular!
files = [
MOCHA,
MOCHA_ADAPTER,
'assets/js/lib/**/*.js',
'test/lib/angular/*.js',
'test/unit/**/*.coffee',
'assets/js/*.coffee',
'node_modules/chai/chai.js'
];
autoWatch = true;
browsers = ['Chrome'];
I list node_modules/chai/chai.js
rather than include it in my sources because I would like chai to be installed via devDependencies
with npm install
.
My test lives in test/unit/coolSpec.coffee
and reads like so:
"use strict"
should = chai.should()
# Mocha/Chai specs for controllers go here
describe "OverviewCtrl", ->
beforeEach ->
ctrl = new OverviewCtrl()
it "should do something awesome.", ->
1.should.be.a 'string'
But testacular fails to find chai
.
Uncaught ReferenceError: chai is not defined
at /.../test/unit/coolSpec.coffee-compiled.js:5
Chrome 25.0 (Linux): Executed 0 of 0 ERROR (0.386 secs / 0 secs)
How can I manage Javascript imports WITHOUT resorting to RequireJS??
EDIT: according to the testacular documentation here the effect of listing a file in the files array is exactly that of inserting a <script>
tag into the browser at test-time. This should mean all symbols are imported.
But then again, maybe that's the issue: http://chaijs.com/chai.js itself was written for RequireJS. I may have no choice but to use it!
Upvotes: 2
Views: 653
Reputation: 26
Go to chai's home page and then select to download the BROWSER version of chai script, not the one for NodeJS.
The direct link to the chai script you can use in the browser for testing is here: http://chaijs.com/chai.js
Upvotes: 1