Skip to content

Instantly share code, notes, and snippets.

@IanBoyanZhang
Last active October 3, 2015 15:58
Show Gist options
  • Save IanBoyanZhang/744811cd8a8010f86a75 to your computer and use it in GitHub Desktop.
Save IanBoyanZhang/744811cd8a8010f86a75 to your computer and use it in GitHub Desktop.
Minimal example of setting up a Chai/Mocha sandbox
describe("Vehicle", function() {
describe("constructor", function() {
it("should have a default type", function() {
var car = new Vehicle();
expect(car.type).to.equal("car");
});
});
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SandBox</title>
<link href='https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css' rel='stylesheet' media="all"/>
</head>
<body>
<div id="mocha"><p><a href=".">Index</a></p></div>
<div id="messages"></div>
<div id="fixtures"></div>
<script src='https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.js'></script>
<script src="http://chaijs.com/chai.js"></script>
<script>
// env setup
(function(exports) {
"use strict";
exports.expect = chai.expect;
})(this);
</script>
<script src="index.js"></script>
<script>mocha.setup('bdd')</script>
<script src="first_test.js"></script>
<script src="second_test.js"></script>
<script>mocha.run();</script>
</body>
</html>
(function(exports) {
"use strict";
function Vehicle(type) {
this.type = type || "car";
}
Vehicle.prototype = {
run: function run(speed) {
if (!speed) {
throw new Error("No speed provided!");
}
return this.type + "is running at" + speed + "mph";
}
};
exports.Vehicle = Vehicle;
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment