visit
visit boots your app into a new element, visits a URL, and waits for Ember to settle. It returns vitest locator selectors scoped to that element.
WARNING
visit is not compatible with @ember/test-helpers. For compatibility with @ember/test-helpers, use one of the additional testing styles.
import { describe, expect, test } from "vitest";
import { visit } from "ember-vitest";
import App from "#app/app";
describe("Home", () => {
test("links to the about page", async () => {
const screen = await visit(App, "/");
await screen.getByRole("link", { name: "About" }).click();
await expect
.element(screen.getByRole("heading"))
.toHaveTextContent("About");
expect(screen.currentURL).toBe("/about");
});
});The app uses location: "none", so the URL of the test page does not change.
WARNING
Each call to visit boots a new app. A second visit(App, url) does not navigate the first app. To navigate, use screen.visit(url).
configure runs after the app boots and before it visits the URL. ApplicationRoute runs after configure, so configure can register stubs that the route uses:
const screen = await visit(App, "/", {
configure(instance) {
instance.register("service:session", StubSession);
},
});The returned screen has:
container, the element that the app renders intoowner, the booted app instance, for example to look up servicescurrentURL, the URL of the appvisit(url), to navigate the same app to another URLlocator, a vitest locator forcontainergetByRole,getByText,getByTestIdand the other locator selectors, scoped tocontainerunmount(), to tear down the app before the test ends
The app is torn down after each test.
Parallel tests
In a concurrent test, pass the test context as { context }. See Parallel tests.
Additional testing styles
visit does not set up an @ember/test-helpers test context. These testing styles set one up:
setupRenderingContext- Extended
test, withapplicationTestfor application tests