setupContext
setupContext boots an instance of your app and returns it as owner. Use the owner to look up services and other objects of your app, or to interact with the app instance.
gjs
import { describe, test, expect } from "vitest";
import { setupContext } from "ember-vitest";
import App from "#app/app";
describe("session service", () => {
test("starts signed out", async () => {
await using ctx = await setupContext(App);
let session = ctx.owner.lookup("service:session");
expect(session.isSignedIn).toBe(false);
});
});Why choose it
Choose setupContext when a test needs an owner but does not render and does not visit a URL.
- Each call boots a separate app instance, so state does not leak between tests.
- It does not set up an
@ember/test-helperscontext. The helpers that render or visit do not apply to these tests. - To render, use
renderwith{ owner: ctx.owner }, or usesetupRenderingContext.
If you pass no app, setupContext boots an empty app.
The context
The context has:
element, the root element of the appowner, the booted app instance
If a test does not dispose its context, the context is torn down after that test.