Skip to content

Instantly share code, notes, and snippets.

@tanmaypatel
Created December 5, 2013 14:10
Show Gist options
  • Select an option

  • Save tanmaypatel/f95318607c2249338d7b to your computer and use it in GitHub Desktop.

Select an option

Save tanmaypatel/f95318607c2249338d7b to your computer and use it in GitHub Desktop.
Simple JS TDD Setup with Mocha and Chai
<!DOCTYPE html>
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]><html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Tests</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="node_modules/mocha/mocha.css"/>
<script type="text/javascript" src="components/requirejs/require.js"></script>
<script type="text/javascript" src="scripts/setup.js"></script>
</head>
<body>
<div id="menu"></div>
<div id="mocha"></div>
<div id="coverage"></div>
</body>
</html>
{
"name": "TDD",
"version": "0.0.0",
"description": "",
"repository": "",
"author": "",
"devDependencies": {
"mocha": "~1.15.1",
"chai": "~1.8.1",
"requirejs": "~2.1.9",
"sinon": "~1.7.3"
}
}
requirejs.config({
baseUrl : './',
paths : {
"require" : "components/requirejs/require",
"modernizr" : "components/modernizr/modernizr",
"jquery" : "components/jquery/jquery-1.10.2",
"underscore" : "components/underscore/underscore",
"backbone" : "components/backbone/backbone",
"mocha" : "node_modules/mocha/mocha",
"chai" : "node_modules/chai/chai",
"sinon" : "node_modules/sinon/lib/sinon"
},
shim : {
"jquery" : {
exports : "$"
},
"underscore" : {
exports : "_"
},
"backbone" : {
deps : [ "underscore", "jquery" ],
exports : "Backbone"
},
"chai" : {
exports : "chai"
},
"mocha" : {
deps : [ "chai" ],
exports : "mocha"
},
"sinon" : {
exports : "sinon"
}
}
});
require([ "require", "chai", "mocha" ],
function(require, chai)
{
assert = chai.assert;
should = chai.should();
expect = chai.expect;
mocha.setup('bdd');
require(['tests/models/UserTest'], function(UserTest)
{
mocha.run();
});
});
define(['jquery', 'underscore', 'backbone'],
function($, _, Backbone)
{
var User = Backbone.Model.extend({
defaults: function()
{
return {
id: -1,
username: '',
firstName: '',
lastName: ''
};
},
initialize: function()
{
},
getFullName: function()
{
return this.get('firstName') + this.get('lastName');
}
});
return User;
});
define(['jquery', 'underscore', 'backbone', 'models/User'],
function($, _, Backbone, User)
{
describe('User', function()
{
describe('initialization', function()
{
it('can be loaded', function()
{
expect(User).not.to.be.undefined;
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment