Extensions to the Jasmine test framework for use with Flight
Include jasmine-flight.js in your app and load it in your test runner.
Or install it with Bower:
bower install --save-dev jasmine-flight
N.B. jasmine-flight depends on jasmine and jasmine-jquery
jasmine-flight assumes you'll be using RequireJS to load Flight modules, and that you've configured the Flight directory path. For example:
requirejs.config({
paths: {
flight: 'bower_components/flight'
}
});
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()).toBe(expected);
});
});
describeComponent('data/twitter_profile', function () {
beforeEach(function () {
setupComponent();
});
describe('listens for uiNeedsTwitterUserId', function () {
// was the event triggered?
it('and triggers dataTwitterUserId', function () {
var eventSpy = spyOnEvent(document, 'dataTwitterProfile');
$(document).trigger('uiNeedsTwitterUserId', {
screen_name: 'tbrd'
});
expect(eventSpy).toHaveBeenTriggeredOn(document);
});
// is the user id correct?
it('and has correct id', function () {
var eventSpy = spyOnEvent(document, 'dataTwitterUserId');
$(document).trigger('uiNeedsTwitteruserId', {
screen_name: 'tbrd'
});
expect(eventSpy.mostRecentCall.data).toEqual({
screen_name: 'tbrd',
id: 4149861
});
});
});
});
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).toHaveClass('foo');
});
});
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).toBe('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.
- @esbie and
@skilldrick for creating the original
describeComponent
&describeMixin
methods. - @necolas for ongoing support & development
Copyright 2013 Twitter, Inc and other contributors.
Licensed under the MIT License