Skip to content

Instantly share code, notes, and snippets.

@rmurphey
Created August 25, 2012 00:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmurphey/3458110 to your computer and use it in GitHub Desktop.
Save rmurphey/3458110 to your computer and use it in GitHub Desktop.

Files would be laid out as follows ... obviously this is a little contrived :)

grunt.js
app/
  index.html
  js/
    foo.js
    runner.js
  tests/
    foo.js
  vendor/
    chai.js
    mocha.js
    jquery.js
    require.js
define([ 'js/foo' ], function(Foo) {
suite('Foo', function() {
test('it works', function() {
assert(true, 'ok');
});
});
});
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
mocha: {
index: ['app/index.html']
}
});
// Default task.
grunt.loadNpmTasks('grunt-mocha');
grunt.registerTask('default', 'lint mocha');
};
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/mocha.css">
<script src="vendor/chai.js"></script>
<script>
window.assert = chai.assert;
</script>
<script src="vendor/mocha.js"></script>
<script>
mocha.setup('tdd');
</script>
<script src="vendor/require.js"></script>
<script>
require.config({
deps : [ 'js/runner' ],
paths : {
'jquery' : 'vendor/jquery'
}
});
</script>
</head>
<body>
<div id="mocha"></div>
<div id="test"></div>
<!-- restore this script tag if you're not using requirejs.
<script>mocha.run();</script>
-->
</body>
</html>
require([
'tests/foo'
], function() {
mocha.run();
});
@svnlto
Copy link

svnlto commented Aug 25, 2012

seems it still doesn't work for me like this. dropping a console.log into the mocha runner gives me:

  [ 'Page error: TypeError: \'undefined\' is not a function (evaluating \'mocha.setup({\n    ui: \'bdd\',\n    ignoreLeaks: true\n  })\')\n  file:///Users/svenlito/Dropbox/Sites/private/outofmede-webapp/tests/app/runner.html:24\n' ] 'debug'
Page error: TypeError: 'undefined' is not a function (evaluating 'mocha.setup({
    ui: 'bdd',
    ignoreLeaks: true
  })')

nevermind, I'll keep digging around. thanks for sharing this anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment