Skip to content
Extensions to the Mocha test framework for use with Flight
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.gitignore
.jshintrc
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
LICENSE.md
README.md
bower.json
karma.conf.js
package.json

README.md

mocha-flight Build Status

Extensions to the Mocha test framework for use with Flight

Installation

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

Usage

These examples use the chai.js assertion library.

Components

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
  });
});

Mixins

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);
  });
});

Event spy

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

setupComponent(optionalFixture, optionalOptions);

Calling setupComponent twice will create an instance, tear it down and create a new one.

HTML Fixtures

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();
  });
});

Component Options

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/');
  });
});

Teardown

Components are automatically torn down after each test.

Contributing to this project

Anyone and everyone is welcome to contribute. Please take a moment to review the guidelines for contributing.

License

Copyright (c) 2013 Naoya Inada naoina@kuune.org

Licensed under the MIT License

You can’t perform that action at this time.