Coder Social home page Coder Social logo

fionawhim / flight-jasmine Goto Github PK

View Code? Open in Web Editor NEW

This project forked from flightjs/jasmine-flight

0.0 1.0 0.0 178 KB

Extensions to the Jasmine test framework for use with Flight

License: MIT License

JavaScript 99.34% CoffeeScript 0.66%

flight-jasmine's Introduction

flight-jasmine Build Status

Extensions to the Jasmine test framework for use with Flight

Getting started

Include flight-jasmine.js in your app and load it in your test runner.

Or install it with Bower:

bower install --save-dev flight-jasmine

N.B. flight-jasmine depends on jasmine and jasmine-jquery

Components

describeComponent('path/to/component', function () {
  beforeEach(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(setupComponent);

  it('should do x', function () {
    expect(this.component.doSomething()).toBe(expected);
  });
});

Event spy

describeComponent('data/twitter_profile', function () {
  beforeEach(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

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).toHaveClass('foo');
  });
});

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).toBe('http://twitter.com/1.1/');
  });
});

Teardown

Components are automatically torn down after each test.

Why flight-jasmine?

Flight components are defined by their interface: the events they trigger and handle, and how they interact with the DOM. They are also highly independent, with no reliance on other components. These two factors allow them to be rigourously and exhaustively tested.

However, Flight does not expose component instances so testing them can be tricky. Also, out-of-the-box Jasmine does not support testing of jQuery Events.

flight-jasmine provides the developer with simple methods for setting up, exposing and tearing down component instances, and for testing whether expected events are triggered.

Contributing to this project

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

Authors

Thanks

License

Copyright 2013 Twitter, Inc and other contributors.

Licensed under the MIT License

flight-jasmine's People

Contributors

caniszczyk avatar necolas avatar simonsmith avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.