Skip to content

Latest commit

 

History

History
49 lines (38 loc) · 1.72 KB

File metadata and controls

49 lines (38 loc) · 1.72 KB
id title
setup
Setup

Vue Testing Library does not require any configuration to be used. However, there are some things you can do when configuring your testing framework to reduce some boilerplate. In these docs we'll demonstrate configuring Jest, but you should be able to do similar things with any testing framework (Vue Testing Library does not require that you use Jest).

Using without Jest

If you're running your tests in the browser bundled with webpack (or similar) then Vue Testing Library should work out of the box for you. However, most people using Vue Testing Library are using it with the Jest testing framework with the testEnvironment set to jest-environment-jsdom (which is the default configuration with Jest).

jsdom is a pure JavaScript implementation of the DOM and browser APIs that runs in Node. If you're not using Jest and you would like to run your tests in Node, then you must install jsdom yourself. There's also a package called jsdom-global which can be used to setup the global environment to simulate the browser APIs.

First, install jsdom and jsdom-global.

npm install --save-dev jsdom jsdom-global

With mocha, the test command would look something like this:

mocha --require jsdom-global/register

Skipping Auto Cleanup

Cleanup is called after each test automatically by default if the testing framework you're using supports the afterEach global (like mocha, Jest, and Jasmine). However, you may choose to skip the auto cleanup by setting the VTL_SKIP_AUTO_CLEANUP env variable to 'true'. You can do this with cross-env like so:

cross-env VTL_SKIP_AUTO_CLEANUP=true jest