Vue
This guide covers how to test Vue applications and components with Rstest. Rstest supports testing Vue in multiple scenarios:
- Node (with happy-dom or jsdom): Fast, lightweight tests running in Node.js with a simulated DOM
- Browser Mode: Real browser testing with Playwright for accurate DOM behavior
Node testing
Node-based testing uses DOM simulators like happy-dom or jsdom to provide a DOM environment in Node.js. This approach is faster and suitable for most component testing scenarios.
Quick start
1. Install dependencies
If you want to use Vue JSX, also install:
2. Configure rstest
Create rstest.config.ts:
For Vue JSX support:
3. Write your first test
Testing components
Use @vue/test-utils to mount and interact with components:
Testing events
Testing Vue JSX components
Vue JSX components can be tested the same way as SFC components:
Mocking modules
Use rs.mock() to mock dependencies:
Browser mode testing
For scenarios requiring real browser behavior (e.g., CSS rendering, Web APIs, visual testing), use Rstest's Browser Mode with Playwright.
See the Browser Testing - Getting Started for detailed setup instructions.
Browser Mode currently provides out-of-the-box support for React. Vue support in Browser Mode will be added in the future.
Recommendations:
- Use Node testing for unit tests, logic-heavy components, and fast feedback
- Use Browser Mode for integration tests, visual behavior, and when you need real browser APIs
Example projects
- vue - Vue testing with happy-dom (includes SFC and JSX tests)