Created
November 11, 2016 23:27
-
-
Save jaycody/04a5562202e52ce4cfec01ad759d9a96 to your computer and use it in GitHub Desktop.
template for automated unit tests with Mocha test runner and Chai assertion library
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
/* eslint-env node, mocha */ | |
import "babel-core/external-helpers"; | |
let chai = require('chai'); | |
chai.should(); | |
chai.expect(); | |
import Point from '../src/oak-roots/Rect'; | |
// calls each test | |
describe('Rect', () => { | |
test_constructor(); | |
test_clone(); | |
test_set(); | |
}); | |
// this test demonstrates: | |
// nested describes and | |
// test results formatting options | |
function test_isPointLike () { | |
let testTypeStr, | |
testTypeBool; | |
beforeEach(() => { | |
//pointThingNaN = { x: NaN, y: NaN }; | |
//pointThingUndefined = { x: undefined, y: undefined }; | |
}); | |
describe('\n--------\n#isPointLike\n', () => { | |
describe('returns false if given...', () => { | |
it('no argument', () => { | |
(Point.isPointLike()).should.equal(false); | |
}); | |
}); | |
describe('returns true if given...', () => { | |
it('an instance of Point class\n', () => { | |
point = new Point(100, 150); | |
(Point.isPointLike(point)).should.equal(true); | |
}); | |
}); | |
}); | |
} | |
function test_constructor () { | |
describe('#constructor()', () => { | |
it('executes with two numerical arguments', () => { | |
let point = new Point(30,40); | |
chai.expect(point.left); | |
}); | |
it('executes when either argument is NaN', () => { | |
let point = new Point(NaN,40); | |
chai.expect(point.left); | |
}); | |
it('executes when invoked with neither x nor y parameter', () => { | |
let point = new Point(); | |
(point.left).should.equal(0); | |
}); | |
}); | |
} | |
// demonstrates calling a function inside a test case | |
function test_right () { | |
describe('#right', () => { | |
let point; | |
beforeEach(() => { | |
point = new Point(10,20); | |
}); | |
it('returns the x-cordinate', () => { | |
}); | |
it('can not be changed', () => { | |
(() => {point.left = 1000}).should.throw(Error); | |
}); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment