The snapshot plugin brings snapshot testing (popularised by Jest) to Japa. The plugin extends the assert and expect modules by adding assertion methods that use either inline snapshots or on-disk snapshots for writing assertions.


You can install the plugin from the npm packages registry as follows.

npm i -D @japa/snapshot

And register it as a plugin within the entry point file, i.e. (bin/test.js)

import { snapshot } from '@japa/snapshot'
import { configure } from '@japa/runner'
files: ['tests/**/*.spec.js'],
plugins: [snapshot()],

If you are using ts-node, then make sure to use the --enable-source-maps flag when running tests. This will ensure that the snapshot plugin can correctly generate the snapshots. See this issue for more details.

Basic usage

Once the plugin has been registered, you can use the toMatchSnapshot and toMatchInlineSnapshot methods for writing assertions.

Usage with Japa Assert
test('match snapshot', async ({ assert }) => {
Usage with Japa Expect
test('match snapshot', async ({ assert, expect }) => {

If you run the above test, a new snapshot will be created inside the tests/__snapshots__ directory with the following contents.

exports['match snapshot 1'] = `"1"`

The snapshots are saved as per the following rules.

  • One snapshot file is created for each test file.
  • The snapshot export combines the test title and a sequence counter. The sequence counter represents the number of snapshot assertions you have in a test.

Inline snapshots

You can use inline snapshots to write the snapshot value inline within the test.

Usage with Japa Assert
test('match snapshot', async ({ expect, assert }) => {
Usage with Japa Expect
test('match snapshot', async ({ expect, assert }) => {

If you run the above test, the snapshot plugin will modify your test file and paste the output of the snapshot inline within the test.

test('match snapshot', async ({ expect, assert }) => {
// with @japa/assert
// with @japa/expect

Updating snapshots

Snapshots, once generated, are treated as the source of truth for future assertions. However, you can update/override them by running your tests with the --update-snapshots CLI flag.

node bin/test.js --update-snapshots
# Or use the alias
node bin/test.js -u

Configuration options

You can configure the snapshot plugin with the following options.

files: ['tests/**/*.spec.js'],
plugins: [
resolveSnapshotPath: (testPath) => {
* This will create a snapshot file next to your
* test file.
return testPath.replace('.spec.ts', '.spec.ts.cjs')
prettyFormatOptions: {
printFunctionName: true


The options to pass to the pretty-format package. This is used to format the snapshot value.


A callback to resolve the location of the snapshot file. By default, the snapshot file is created inside the __snapshots__ directory next to the test file.