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

@eflexsystems/ember-mocha

v5.0.1

Published

Mocha helpers for testing Ember.js applications

Downloads

58

Readme

ember-mocha2

Latest NPM release TravisCI Build Status

ember-mocha2 simplifies testing of Ember applications with Mocha by providing Mocha-specific wrappers around the helpers contained in @ember/test-helpers.

Compatibility

  • Ember.js v3.16 or above
  • Ember CLI v3.16 or above
  • Node.js 10 or above

Installation

ember-mocha2 is an Ember CLI addon, so install it as you would any other addon:

$ ember install ember-mocha2

or

$ yarn add ember-mocha2 --dev

if you want to keep ember-mocha you can point it at the ember-mocha-compat branch in your package.json.

"devDependencies": {
  "ember-mocha": "yads/ember-mocha#ember-mocha-compat"
}

Usage

The following section describes the use of Ember Mocha with the latest modern Ember testing APIs, as laid out in the RFCs 232 and 268.

Setting the Application

Your tests/test-helper.js file should look similar to the following, to correctly setup the application required by @ember/test-helpers:

import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-mocha';
import chai from 'chai';
import chaiDom from 'chai-dom';
chai.use(chaiDom)

setApplication(Application.create(config.APP));
start();

Also make sure that you have set ENV.APP.autoboot = false; for the test environment in your config/environment.js.

Setup Tests

The setupTest() function can be used to setup a unit test for any kind of "module/unit" of your application that can be looked up in a container.

It will setup your test context with:

  • this.owner to interact with Ember's Dependency Injection system
  • this.set(), this.setProperties(), this.get(), and this.getProperties()
  • this.pauseTest() method to allow easy pausing/resuming of tests

For example, the following is a unit test for the SidebarController:

import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from 'ember-mocha';

describe('SidebarController', function() {
  setupTest();

  // Replace this with your real tests.
  it('exists', function() {
    let controller = this.owner.lookup('controller:sidebar');
    expect(controller).to.be.ok;
  });
});

If you find that test helpers from other addons want you to pass a hooks object you can do so like this:

let hooks = setupTest();
setupMirage(hooks);

This will make sure that in functions passed to hooks.afterEach() the this.owner and other things that setupTest() sets up are still available. Mocha itself runs afterEach hooks in a different order than QUnit, which is why this "workaround" is sometimes needed.

Sometimess you will need to specify that tests should not wait for settled state. If you see timeout errors in an afterEach hook for your tests update your setupTest cal:

describe('SidebarController', function() {
  setupTest({ waitForSettled: false });

Setup Rendering Tests

The setupRenderingTest() function is specifically designed for tests that render arbitrary templates, including components and helpers.

It will setup your test context the same way as setupTest(), and additionally:

  • Initializes Ember's renderer to be used with the Rendering helpers, specifically render()
  • Adds this.element to your test context which returns the DOM element representing the wrapper around the elements that were rendered via render()
  • sets up the DOM Interaction Helpers from @ember/test-helpers (click(), fillIn(), ...)
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupRenderingTest } from 'ember-mocha';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

describe('GravatarImageComponent', function() {
  setupRenderingTest();

  it('renders', async function() {
    await render(hbs`{{gravatar-image}}`);
    expect(this.element.querySelector('img')).to.exist;
  });
});

Setup Application Tests

The setupApplicationTest() function can be used to run tests that interact with the whole application, so in most cases acceptance tests.

On top of setupTest() it will:

import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupApplicationTest } from 'ember-mocha';
import { visit, currentURL } from '@ember/test-helpers';

describe('basic acceptance test', function() {
  setupApplicationTest();

  it('can visit /', async function() {
    await visit('/');
    expect(currentURL()).to.equal('/');
  });
});

Upgrading

For instructions how to upgrade your test suite please read our Migration Guide.

Contributing

Contributions are welcome. Please follow the instructions below to install and test this library.

Installation

yarn

Testing

In order to test in the browser:

yarn test --server

In order to perform a CI test:

yarn test

Copyright and License

Copyright 2014 Switchfly

This product includes software developed at Switchfly (http://www.switchfly.com).

NOTICE: Only our own original work is licensed under the terms of the Apache License Version 2.0. The licenses of some libraries might impose different redistribution or general licensing terms than those stated in the Apache License. Users and redistributors are hereby requested to verify these conditions and agree upon them.