> For the complete documentation index, see [llms.txt](/llms.txt).

# Test a Snap

You can test your Snap [locally](#test-locally), in the [Snaps sandbox](#test-in-the-sandbox), and [end-to-end using Jest](#test-end-to-end).

## Test locally[​](#test-locally "Direct link to Test locally")

1. Host your Snap locally:  
```  
yarn start  
```
2. Install your Snap in Flask.
3. Test your Snap by calling its API methods from a dapp.

## Test in the sandbox[​](#test-in-the-sandbox "Direct link to Test in the sandbox")

Use the Snaps sandbox to test and debug your Snap in an easy-to-use interface.

1. Run the [sandbox](/snaps/reference/cli/#sandbox) subcommand to start the sandbox server:  
```  
yarn mm-snap sandbox  
```  
Navigate to the `localhost` URL displayed in the terminal.
2. Install your Snap in Flask.
3. Test your Snap by calling its API methods from the sandbox interface.

## Test end-to-end[​](#test-end-to-end "Direct link to Test end-to-end")

Follow these steps to test your Snap end-to-end in a Jest environment.

### 1. Install `@metamask/snaps-jest`[​](#1-install-metamasksnaps-jest "Direct link to 1-install-metamasksnaps-jest")

Install the [@metamask/snaps-jest](https://github.com/MetaMask/snaps/tree/main/packages/snaps-jest) package into your Snap project using [Yarn](https://yarnpkg.com/)or [npm](https://www.npmjs.com/):

```
yarn add -D @metamask/snaps-jest

```

or

```
npm i @metamask/snaps-jest

```

### 2. Configure `@metamask/snaps-jest`[​](#2-configure-metamasksnaps-jest "Direct link to 2-configure-metamasksnaps-jest")

The easiest way to configure this package is to add it to your Jest configuration as a preset. In the `jest.config.js` file, add the following:

jest.config.js

```
module.exports = {
  preset: '@metamask/snaps-jest',
}

```

This automatically configures Jest to use the `@metamask/snaps-jest` environment, and to use the `@metamask/snaps-jest` matchers. You can then run the `jest` command as usual.

note

`@metamask/snaps-jest` assumes the Snap is built in the directory you run Jest from. If you use a different directory, you can specify the path using the [server.root](/snaps/reference/config-options/#serverroot) option, or by running your own HTTP server. It's currently not possible to use `@metamask/snaps-jest` with a Snap that is not built.

If you don't use the package as a preset, you can alternatively add the `@metamask/snaps-jest`environment and matchers to your Jest configuration manually:

jest.config.js

```
module.exports = {
  testEnvironment: '@metamask/snaps-jest',
  setupFilesAfterEnv: ['@metamask/snaps-jest/dist/cjs/setup.js'],
}

```

You can pass any [Jest options](/snaps/reference/jest/#options) to the test environment by adding a `testEnvironmentOptions` property to your Jest configuration. For example:

jest.config.js

```
module.exports = {
  preset: '@metamask/snaps-jest',
  testEnvironmentOptions: {
    // Options go here.
  },
}

```

All options are optional.

### 3. Use `@metamask/snaps-jest`[​](#3-use-metamasksnaps-jest "Direct link to 3-use-metamasksnaps-jest")

Use the package by calling any of the [API methods](/snaps/reference/jest/#api-methods). For example, you can:

- [Install a Snap.](/snaps/reference/jest/#installsnap)
- [Send a transaction to the Snap.](/snaps/reference/jest/#ontransaction)
- [Run a cron job in the Snap.](/snaps/reference/jest/#oncronjob)
- [Interact with user interfaces.](/snaps/reference/jest/#getinterface)

You can also use [Jest matchers](/snaps/reference/jest/#jest-matchers) to assert that a response from a Snap matches an expected value.
