Skip to main content
inertia-server provides testing utilities that work with your test setup. You can use the utilities for response parsing and assertions, or delegate the latter part to your test framework.

Getting Started

There two functions used for testing:
The inertia function accepts a Response object, a HTML string or a Inertia page object and returns assertion utils. If you are going to chain requests, for exmaple to load deferred props, inertia function takes an option object as a second argument that contains the fetch function. You will have to provide it to instruct the assertion utils, how to communicate with your app.
If you don’t do it, inertia-server will try to infer your server address from the response you give it, otherwise it will throw an error. You can also use the createAppHelper function to create a inertia function that will be bound to your app, so there is no need to pass the fetch function every time.

Assertions

inertia-server comes with a set of basic assertions to test your page. If they are not enough for you, see the tap helper.
All assertions support dot notation for nested properties, i.e. user.profile.name is the same as user['profile']['name'].

Checking Props

Use has() to assert that a prop exists:
You can also check for a specific value:
Or use a callback for custom validation:
has compares values deeply, but it’s a strict equality check. It will fail if the value is not exactly the same.

Missing Props

To assert that a prop does not exist, use the missing method.

Flash and Errors

Flash messages and errors are just props, so you can assert them using has() and missing():

Page Metadata

Assert component name, URL, or version:

Custom Assertions

Use tap() to run custom assertions with direct access to the page object. If you don’t want to use package specific assertions, you can use this method to run your own.
This is useful when you need to use your test framework’s assertion methods or perform complex validations.

Partial Reloads

Test partial reload behavior by making follow-up requests with specific props.

Reload Only

Request only specific props:
With a callback:

Reload Except

Request all props except specific ones:

Deferred Props

Test deferred prop loading:
Load specific groups:

Extracting Data

You can use inertia utils to help you with parsing your responses, and not use its assertion features at all.

Get Props

Extract props for use in other assertions:

Get Page Object