Last active
February 13, 2017 23:07
-
-
Save yanneves/93a41bd38923e4bc247d to your computer and use it in GitHub Desktop.
Mocha Programmatic API w/ JSPM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | |
<title>Example Mocha Test</title> | |
</head> | |
<body> | |
<!-- Required for browser reporter --> | |
<div id="mocha"></div> | |
<!-- Configure and run tests --> | |
<script src="mocha.bundle.js" type="text/javascript" charset="utf-8"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// build using JSPM to mocha.bundle.js | |
// dependencies | |
import mocha from 'mocha' | |
import chai, {expect} from 'chai' | |
// setup mocha | |
mocha.setup('bdd') | |
// test specifications | |
import wombat from './wombat.spec' | |
wombat() | |
// run mocha | |
mocha.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// as found in grunt-mocha example | |
// https://github.com/kmiyashiro/grunt-mocha/blob/master/example/js/wombat.js | |
export default function(opts) { | |
console.log('Log option works') | |
opts = opts || {} | |
this.name = opts.name || 'Wally' | |
this.eat = function(food) { | |
if (!food) throw Error('D:') | |
return 'nom nom' | |
} | |
return this | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// as found in grunt-mocha example | |
// https://github.com/kmiyashiro/grunt-mocha/blob/master/example/test/spec/wombat.js | |
import Wombat from './wombat' | |
export default function () { | |
describe('Wombat', function() { | |
beforeEach(function() { | |
this.wombat = new Wombat() | |
}) | |
afterEach(function() { | |
delete this.wombat | |
}) | |
it('should create a wombat with defaults', function() { | |
expect(this.wombat).property('name', 'Wally') | |
}) | |
it('should name itself if name passed in options', function() { | |
this.wombat = new Wombat({ name: 'Matt' }) | |
expect(this.wombat).property('name', 'Matt') | |
}) | |
describe('#eat', function() { | |
it('should throw if no food passed', function() { | |
expect(this.wombat.eat).to.throw('D:') | |
}) | |
it('should return noms if food passed', function() { | |
expect(this.wombat.eat('apple')).to.eql('nom nom') | |
}) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment