setupTest()

Configures a unit/container test with an application instance and DI access.

Since Ember 4/5 (Octane) Spec ↗

Syntax

setupTest(hooks)

Parameters

NameTypeRequiredDescription
hooks NestedHooks No The QUnit module hooks object.

Returns

void — Wires up owner and teardown for the module.

Examples

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('Unit | Service | session', function (hooks) {
  setupTest(hooks);

  test('it tracks the current user', function (assert) {
    const session = this.owner.lookup('service:session');
    session.login({ name: 'Ada' });
    assert.true(session.isAuthenticated);
  });
});

Notes

Use setupTest for unit and container tests (services, routes, models). Resolve objects via this.owner.lookup(). For DOM rendering use setupRenderingTest instead.