npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jasmine-flight

v4.0.0

Published

Extensions to the Jasmine test framework for use with [Flight](https://github.com/flightjs/flight)

Downloads

18

Readme

jasmine-flight Build Status

Extensions to the Jasmine test framework for use with Flight

Getting started

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

jasmine-flight depends on jasmine

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

What is jasmine-flight?

jasmine-flight provides a set of helpers to load and instantiate AMD components, mixins and modules.

describe helpers

describeComponent(componentPath, specDefinitions)

Requires the component at componentPath and executes specDefinitions.

  • The component constructor is available from within specDefinitions as this.Component
  • To create a component instance, call this.setupComponent

componentPath: String

A path to an AMD component. E.g. ui/compose

specDefinitions: Function

A function to execute after the component has loaded. Should contain spec definitions.

ddescribeComponent(componentPath, specDefinitions)

As per describeComponent, but prevents execution of any other specs.

describeMixin(mixinPath, specDefinitions)

Requires the mixin at mixinPath and executes specDefinitions.

  • The Mixin is attached to a dummy Component
  • the dummy Component constructor is available from within specDefinitions as this.Component
  • To create a component instance, call this.setupComponent

mixinPath: String

A path to an AMD mixin. E.g. ui/with_close_button

specDefinitions: Function

A function to execute after the mixin has loaded. Should contain spec definitions.

ddescribeMixin(mixinPath, specDefinitions)

As per describeMixin, but prevents execution of any other specs.

describeModule(modulePath, specDefinitions)

Requires the AMD module at modulePath and executes specDefinitions

  • The module will be available as this.module from within specDefinitions.

modulePath: String

A path to an AMD module. E.g. utils/time

specDefinitions: Function

A function to execute after the module has loaded. Should contain spec definitions.

ddescribeModule(modulePath, specDefinitions)

As per describeModule, but prevents execution of any other specs.

this.setupComponent(fixture, options)

Instantiate a component or mixin within specDefinitions.

  • The component instance is available at this.component
  • The node the component is attached to is this.$node

fixture: String | jQuery

Generates a DOM element to attach the component to. If no fixture is provided, the component will be attached to an empty DOM node.

options: Object

Options to pass to the component.

Examples

In almost all cases, describeMixin and describeComponent are effectively identical in their usage, thus only describeComponent is detailed here.

describeComponent with fixture

This spec tests a simple component which has one methomd, 'getName', which returns the value of an input field.

describeComponent('ui/text_input', function () {
  it ('gets the value of the input field it is attached to', function () {
    this.setupComponent('<input type="text" value="hello world" />');
    expect(this.component.getValue()).toEqual('hello, world');
  });
});

describeComponent with options

This spec tests a component which has one method, getText, which gets the text value of an element. It uses options to figure out which element to access.

describeComponent('ui/text', function () {
  it ('gets the text of the element specified by elementSelector', function () {
    this.setupComponent('<div><p class="js-name">Jimmy</p></div>', {
      elementSelector: 'js-name'
    });
    expect(this.component.getText()).toEqual('Jimmy');
  });
});

Stubbing mixin methods

When testing components, you may want to stub out methods provided by mixins. In this example, we're stubbing a method named 'foo' (which was provided by a mixin) so that it always returns 'bar'.

describeComponent('ui/text', function () {
  it ('foo returns "foo"', function () {
    this.setupComponent();
    var stub = spyOn(this.component, 'foo').andReturn('bar');
    expect(this.component.foo()).toEqual('bar');
  });
});

Stubbing component methods

It's probably not a good idea to stub out methods on the component you're testing, but if you really, really want to...

describeComponent('ui/text', function () {
  it('calls the stub instead', function () {
    // spy on the prototype...
    var spy = spyOn(this.Component.prototype, 'getText');

    // ... and then instantiate the component
    this.setupComponent();

    expect(spy).toHaveBeenCalled();
  });
});

Spying on events

Event Spies are not part of this package but are mentioned here because it's mostly what you'll be wanting to do. spyOnEvent and the associated matchers are provided by https://github.com/velesin/jasmine-jquery

describeComponent('ui/text', function () {
  it('triggers 'data-username' after initialize', function () {
    var spyEvent = spyOnEvent(document, 'data-username');
    this.setupComponent({
      username: 'bob'
    });
    expect('data-username').toHaveBeenTriggeredOnAndWith(document, {
      username: 'bob'
    });
  });
});

Contributing to this project

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

Authors

Thanks

  • @esbie and @skilldrick for creating the original describeComponent & describeMixin methods.
  • @necolas for ongoing support & development

License

Copyright 2013 Twitter, Inc and other contributors.

Licensed under the MIT License