Socket
Socket
Sign inDemoInstall

@vue/test-utils

Package Overview
Dependencies
54
Maintainers
5
Versions
119
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @vue/test-utils

Utilities for testing Vue components.


Version published
Weekly downloads
1.7M
increased by11.53%
Maintainers
5
Install size
8.00 MB
Created
Weekly downloads
 

Package description

What is @vue/test-utils?

@vue/test-utils is the official unit testing utility library for Vue.js. It provides methods to mount and interact with Vue components in an isolated manner, allowing developers to write unit tests for their Vue components effectively.

What are @vue/test-utils's main functionalities?

Mounting Components

Mounting components allows you to render a Vue component in a test environment and returns a wrapper that contains the mounted component and methods to interact with it.

import { mount } from '@vue/test-utils';
import MyComponent from './MyComponent.vue';

const wrapper = mount(MyComponent);

Finding Elements

Finding elements within the mounted component using CSS selectors, Vue component options, or ref attributes, which can then be used to test the component's behavior.

const button = wrapper.find('button');

Simulating User Interaction

Simulating user interactions such as clicks, typing, or other events on the mounted component to test how it responds to user input.

button.trigger('click');

Accessing Component Data and Methods

Accessing the Vue instance's data, computed properties, and methods to assert their values and behavior within the test.

const vm = wrapper.vm;
console.log(vm.someData);

Stubbing Child Components

Stubbing child components to prevent their actual implementation from being rendered, which can simplify tests and improve test performance.

const wrapper = mount(MyComponent, {
  stubs: {
    ChildComponent: true
  }
});

Other packages similar to @vue/test-utils

Readme

Source

Vue Test Utils Build Status

Currently in beta

To use Vue Test Utils beta:

// npm
npm install --save-dev @vue/test-utils

// yarn
yarn add --dev @vue/test-utils

Intro

Vue Test Utils is the official test library for Vue.js. It provides methods for unit testing Vue components.

Documentation

Refer to the documentation

Examples

Questions

For questions and support please use the Discord chat room, Gitter chat room, or the official forum. The issue list of this repo is exclusively for bug reports and feature requests.

Issues

Please make sure to read the Issue Reporting Checklist before opening an issue. Issues not conforming to the guidelines may be closed immediately.

License

MIT

FAQs

Last updated on 27 Jan 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc