8.0.2 • Published 5 months ago

ember-qunit v8.0.2

Weekly downloads
173,429
License
MIT
Repository
github
Last release
5 months ago

ember-qunit

Latest NPM release CI Build Status

ember-qunit simplifies testing of Ember applications with QUnit by providing QUnit-specific wrappers around the helpers contained in ember-test-helpers.

Requirements

  • Ember.js v4.0 or above
  • Ember Auto Import v2 or above (or Embroider)
  • Node.js v16 or above
  • TypeScript 4.8 and 4.9
  • ember-cli ~v4.8.1, ~v4.12.2, >= v5.1

If you need support for Node 14 please use v6.2 of this addon.

If you need support for Node 13 or older Ember CLI versions please use v4.x of this addon.

Installation

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

$ ember install ember-qunit

Some other addons are detecting the test framework based on the installed addon names and are expecting ember-cli-qunit instead. If you have issues with this then ember install ember-cli-qunit, which should work exactly the same.

Upgrading

For instructions how to upgrade to the latest version, please read our Migration Guide.

Usage

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

For the older APIs have a look at our Legacy Guide.

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-qunit';

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 { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('SidebarController', function(hooks) {
  setupTest(hooks);

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

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:

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, find } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('GravatarImageComponent', function(hooks) {
  setupRenderingTest(hooks);

  test('renders', async function() {
    await render(hbs`{{gravatar-image}}`);
    assert.ok(find('img'));
  });
});

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 { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { visit, currentURL } from '@ember/test-helpers';

module('basic acceptance test', function(hooks) {
  setupApplicationTest(hooks);

  test('can visit /', async function(assert) {
    await visit('/');
    assert.equal(currentURL(), '/');
  });
});

Configuration

Configuration is optionally managed via @embroider/macros

To configure ember-qunit, in your ember-cli-build.js, add:

'use strict';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function (defaults) {
  const app = new EmberApp(defaults, {
    '@embroider/macros': {
      setConfig: {
        'ember-qunit': {
          /**
           * default: false
           *
           * removes the CSS for the test-container (where the app and components are rendered to)
           */
          disableContainerStyles: true,
        },
      },
    },
    /* ... */ 
  });

  /* ... */
};

Contributing

Installation

  • git clone <repository-url>
  • cd ember-qunit
  • pnpm install

Running tests

  • pnpm test (Runs ember try:each to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Running the dummy application

For more information on using ember-cli, visit https://ember-cli.com/.

8.0.2

5 months ago

8.0.1

7 months ago

8.0.0

7 months ago

7.0.0

10 months ago

7.1.0-0

10 months ago

6.2.0

1 year ago

6.1.0

1 year ago

6.1.1

1 year ago

6.0.0

1 year ago

5.1.5

2 years ago

5.1.4

3 years ago

5.1.3

3 years ago

5.1.2

3 years ago

5.1.1

3 years ago

5.1.0

3 years ago

5.0.0

3 years ago

5.0.0-beta.5

3 years ago

5.0.0-beta.4

4 years ago

5.0.0-beta.3

4 years ago

5.0.0-beta.2

4 years ago

5.0.0-beta.1

4 years ago

4.6.0

4 years ago

4.5.1

5 years ago

4.5.0

5 years ago

4.4.1

5 years ago

4.4.0

5 years ago

4.3.0

5 years ago

4.2.0

5 years ago

4.1.2

5 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.0

5 years ago

3.5.3

5 years ago

3.5.2

5 years ago

3.5.1

5 years ago

3.5.0

5 years ago

3.4.2

5 years ago

3.4.1

6 years ago

3.4.0

6 years ago

3.3.2

6 years ago

3.3.1

6 years ago

3.3.0

6 years ago

3.2.2

6 years ago

3.2.1

6 years ago

3.2.0

6 years ago

3.1.0

6 years ago

3.0.0

6 years ago

3.0.0-beta.8

6 years ago

3.0.0-beta.7

6 years ago

3.0.0-beta.6

6 years ago

3.0.0-beta.5

6 years ago

3.0.0-beta.4

6 years ago

3.0.0-beta.3

6 years ago

3.0.0-beta.2

6 years ago

3.0.0-beta.1

6 years ago

2.2.0

7 years ago

2.1.4

7 years ago

2.1.3

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

0.4.24

7 years ago

0.4.23

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

2.0.0-beta.1

7 years ago

1.0.0

7 years ago

1.0.0-beta.1

8 years ago

0.4.22

8 years ago

0.4.21

8 years ago

0.4.20

8 years ago

0.4.19

8 years ago

0.4.18

8 years ago

0.2.0

9 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago