Extensions to the Mocha test framework for use with Flight
We recommend that you use Bower:
bower install --save-dev mocha-flight
Alternatively, you can include mocha-flight.js in your app and load it in your test runner.
N.B. mocha-flight depends on Mocha
These examples use the chai.js assertion library.
describeComponent('path/to/component', function () {
beforeEach(function () {
setupComponent();
});
it('should do x', function () {
// a component instance is now accessible as `this.component`
// the component root node is attached to the DOM
// the component root node is also available as this.$node
});
});
describeMixin('path/to/mixin', function () {
// initialize the component and attach it to the DOM
beforeEach(function () {
setupComponent();
});
it('should do x', function () {
expect(this.component.doSomething()).to.equal(expected);
});
});
You will need to use a library like sinon.js.
describeComponent('path/to/component', function () {
beforeEach(function () {
setupComponent();
});
it('should do x', function () {
sinon.stub(this.component, 'method');
// You need to initialize the component after stubbing the function so the
// event will be bound and call the stubbed callback function
initializeComponent();
$(document).trigger('EVENT_NAME');
this.component.method.calledOnce.should.be.true;
done();
});
});
setupComponent(optionalFixture, optionalOptions);
Calling setupComponent
twice will create an instance, tear it down and create a new one.
describeComponent('ui/twitter_profile', function () {
// is the component attached to the fixture?
it('this.component.$node has class "foo"', function () {
setupComponent('<span class="foo">Test</span>');
expect(this.component.$node.find('span').hasClass('foo')).to.be.ok();
});
});
describeComponent('data/twitter_profile', function() {
// is the option set correctly?
it('this.component.attr.baseUrl is set', function() {
setupComponent({
baseUrl: 'http://twitter.com/1.1/'
});
expect(this.component.attr.baseUrl).to.equal('http://twitter.com/1.1/');
});
});
Components are automatically torn down after each test.
Anyone and everyone is welcome to contribute. Please take a moment to review the guidelines for contributing.
Copyright (c) 2013 Naoya Inada [email protected]
Licensed under the MIT License