Frontend UNIT Testing
Karma + Mocha + Chai
by @passy
Unit
NOt Integration tests
Not acceptance tests
Yet
Maybe next time.
Mocha
Mocha is a feature-rich JavaScript test framework running on node and the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases.
var assert = require('assert'); // External dependency!
describe('Array', function () {
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function() {
assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));
});
});
});
Chai
Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.
var assert = require('chai').assert
, foo = 'bar'
, beverages = { tea: [ 'chai', 'matcha', 'oolong' ] };
assert.typeOf(foo, 'string', 'foo is a string');
assert.equal(foo, 'bar', 'foo equal `bar`');
assert.lengthOf(foo, 3, 'foo`s value has a length of 3');
assert.lengthOf(beverages.tea, 3, 'beverages has 3 types of tea');
Karma
Spectacular Test Runner for JavaScript
From the AngularJS team. <3
Frontend Unit Testing
By Pascal
Frontend Unit Testing
- 2,186