Skip to content

Instantly share code, notes, and snippets.

@lazd
Created October 16, 2012 18:12
Show Gist options
  • Save lazd/3900997 to your computer and use it in GitHub Desktop.
Save lazd/3900997 to your computer and use it in GitHub Desktop.
grunt-mocha test failure
/*global module:false*/
module.exports = function(grunt) {
// External tasks
grunt.loadNpmTasks('grunt-mocha');
grunt.initConfig({
// Configure
mocha: {
cui: {
run: true,
src: [
'index.html'
]
}
}
});
// Default task
grunt.registerTask('default', 'mocha');
};
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<!-- Mocha CSS -->
<link rel="stylesheet" href="libs/mocha/mocha.css" />
<!-- Chai -->
<script src="libs/chai/chai.js"></script>
<script>
var assert = chai.assert;
var expect = chai.expect;
</script>
<!-- Mocha -->
<script src="libs/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>
</head>
<body>
<div id="mocha"></div>
<!-- Tests: Included in body -->
<script src="test.part1.js"></script>
<script src="test.part2.js"></script>
<!-- Do test run -->
<script>
(window.mochaPhantomJS || mocha).run();
</script>
</body>
</html>
describe('window.location', function() {
// The following causes mocha-grunt to not catch failures in the next test script!
it('should be defined', function() {
expect(window).to.have.property('location');
});
describe('location', function() {
it('should have hash', function() {
expect(window.location).to.have.property('hash');
});
});
});
describe('window.navigator', function() {
describe('user agent', function() {
it('should have james bond', function() {
expect(window.navigator).to.have.property('jamesBond');
});
});
});
@lazd
Copy link
Author

lazd commented Oct 16, 2012

You need the following files for this to work:

libs/mocha/mocha.js
libs/chai/chai.js

Running the tests in the browser results in the window.navigator.jamesBond test to fail, running with grunt-mocha causes all tests to pass.

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