public
Last active

Mocha HTML spec

  • Download Gist
admin.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="../libs/mocha.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<body>
<div id="mocha"></div>
<script src="../libs/mocha.js" type="text/javascript" charset="utf-8"></script>
<script src="../libs/sinon.js" type="text/javascript" charset="utf-8"></script>
 
<!-- Common config -->
<script src="../config.js" type="text/javascript" charset="utf-8"></script>
<!-- Admin config -->
<script src="config.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/libs/require/require.js" type="text/javascript" charset="utf-8"></script>
 
<script src="../spec-helpers.js" type="text/javascript" charset="utf-8"></script>
 
<script type="text/javascript" charset="utf-8">
require([
'specs/app.js',
'specs/configBundle.js',
'specs/device.js',
'specs/email.js',
'specs/group.js',
'specs/map.js',
'specs/modal.js',
'specs/policy.js',
'specs/user.js',
'specs/util.js'
], runMocha);
</script>
</body>
</html>
app.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
define(function(require) {
var UploadApp = require('view/apps/uploadAppDialog'),
modalShared = require('../shared/modal.js');
describe('App', function() {
describe('Model', function() {
});
describe('Collection', function() {
});
describe('Views', function() {
describe('Upload App', function() {
before(function() {
this.view = new UploadApp();
// This disables the animation, which breaks during the test.
// Most likely because it requires CSS
this.view.$el.removeClass('fade');
});
after(function() {
this.view.close({ remove: true });
this.view = undefined;
});
 
modalShared();
});
});
});
});
common.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12
// Include and setup all the stuff for testing
define(function(require) {
window.$ = window.jQuery = require('jquery');
window.chai = require('chai');
window.expect = chai.expect;
window.assert = chai.assert;
window.sinonChai = require('sinon-chai'); // Buggy as hell right now
window.jqueryChai = require('chai-jquery');
chai.use(sinonChai);
chai.use(jqueryChai);
});
config.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
// Partial config file
var require = {
// Base URL relative to the test runner
// Paths are relative to this
baseUrl: '../../js/',
paths: {
// Testing libs
'chai' : '../test/libs/chai',
'sinon-chai' : '../test/libs/sinon-chai',
'chai-jquery' : '../test/libs/chai-jquery',
'common' : '../test/libs/common',
'fixtures' : '../test/admin/fixtures/fixtures',
'jquery' : 'libs/jquery/jquery.min',
'underscore' : 'libs/underscore/underscore',
'backbone' : 'vendor/backbone',
'visualsearch' : 'libs/backbone/visualsearch',
'highcharts' : 'libs/highcharts/highcharts',
'charts' : 'vendor/highcharts',
'templates' : 'templates/templates'
},
use: {
backbone: {
deps: ['use!underscore', 'jquery'],
attach: 'Backbone'
},
'libs/backbone/backbone': {
deps: ['use!underscore', 'jquery'],
attach: 'Backbone'
},
'libs/leaflet/leaflet-src': {
attach: 'L'
},
underscore: {
attach: '_'
},
mocha: {
attach: 'mocha'
}
},
priority: [
'jquery',
'underscore',
'common'
]
// urlArgs: /debug\=1/.test(window.location.search) ? '' : 'bust=' + (new Date()).getTime(), // debug
};
 
// You can do this in the grunt config for each mocha task, see the `options` config
mocha.setup({
ui: 'bdd',
ignoreLeaks: true
});
 
// Protect from barfs
console = window.console || function() {};
 
// Don't track
window.notrack = true;
 
// Mocha run helper, used for browser
var runMocha = function() {
mocha.run();
};

Hey man, might be good to update this to reflect shim instead of use.js; really useful reference!

Please, can you provide the GruntFile along the other files?
Thanks a lot.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.