- Impara
-
Ecosistema
Aiuto
Tooling
Librerie Core
Novità
Risorse
- Team
- Supporta Vue
- Traduzioni
Guide
Essenziale
- Installation
- Introduction
- The Vue Instance
- Template Syntax
- Computed Properties and Watchers
- Class and Style Bindings
- Conditional Rendering
- List Rendering
- Event Handling
- Form Input Bindings
- Components
Animazioni e transizioni
- Enter/Leave & List Transitions
- State Transitions
Riusabilità e Composizione
- Mixins
- Custom Directives
- Render Functions & JSX
- Plugins
- Filters
Tooling
- Production Deployment
- Single File Components
- Unit Testing
- TypeScript Support
Scaling Up
- Routing
- State Management
- Server-Side Rendering
Internals
- Reactivity in Depth
Migrazioni
- Migration from Vue 1.x
- Migration from Vue Router 0.7.x
- Migration from Vuex 0.6.x to 1.0
Meta
- Comparison with Other Frameworks
- Join the Vue.js Community!
- Meet the Team
Unit Testing
Setup and Tooling
Anything compatible with a module-based build system will work, but if you’re looking for a specific recommendation try the Karma test runner. It has a lot of community plugins, including support for Webpack and Browserify. For detailed setup please refer to each project’s respective documentation. These example Karma configurations for Webpack and Browserify can help you get started.
Simple Assertions
You don’t have to do anything special in your components to make them testable. Export the raw options:
<template> |
Then import the component options along with Vue, and you can make many common assertions:
// Import Vue and the component being tested |
Writing Testable Components
A component’s render output is primarily determined by the props they receive. If a component’s render output solely depends on its props it becomes straightforward to test, similar to asserting the return value of a pure function with different arguments. Take a simplified example:
<template> |
You can assert its render output with different props using the propsData
option:
import Vue from 'vue' |
Asserting Asynchronous Updates
Since Vue performs DOM updates asynchronously, assertions on DOM updates resulting from state change will have to be made in a Vue.nextTick
callback:
// Inspect the generated HTML after a state update |
We are planning to work on a collection of common test helpers to make it easier to render components with different constraints (e.g. shallow rendering that ignores child components) and assert their output.