Setting up your Nuxt test environment
In each describe block where you are taking advantage of the @nuxt/test-utils helper methods, you will need to set up the test context before beginning.
import { setupTest } from '@nuxt/test-utils'
describe('My test', () => {
setupTest({
// test context options
})
test('my test', () => {
// ...
})
})
Behind the scenes, setupTest performs a number of tasks in beforeEach, afterEach and afterAll to setup the Nuxt test environment correctly. It also adds a single Nuxt setup task as an additional test. This means it must be run within the describe block of a test, before any other calls to test or it.
Using test.only or it.only later in the describe block of your test will cause the tests to fail.
setupTestThe name of the Nuxt configuration file that will be read to get the configuration for the tests.
string'nuxt.config.js'You can override Nuxt options when running tests using this option.
NuxtConfig{}The parent directory for the test fixture.
string'~~/test'(For module or library testing) specifies the name of a fixture directory (under testDir) containing a Nuxt app.
string'fixture'The path to the Nuxt application that will be used in the tests.
string<testDir>/<fixture>By default, build directories are randomised to allow jest to run tests in parallel without conflict.
string<rootDir>/.nuxt/<randomID>The amount of time (in milliseconds) to allow for setupTest to complete its work (which could include building or generating files for a Nuxt application, depending on the options that are passed).
number60000An additional aount of time (in milliseconds) to wait after setting up the test context before commencing the rest of the test suite.
number0Whether to launch a server to respond to requests in the test suite.
booleanfalseWhether to run a separate build step.
booleanfalse (true if browser or server is enabled)Whether to run generate pre-rendered HTML files for the application.
booleanfalseUnder the hood, Nuxt test utils uses playwright to carry out browser testing. If this option is set, a browser will be launched and can be controlled in the subsequent test suite. (More info can be found here.)
booleanfalseobject with the following properties
chromium, firefox or webkitobject of options that will be passed to playwright when launching the browser. See full API reference.