# vue-testing-library **Repository Path**: mirrors_testing-library/vue-testing-library ## Basic Information - **Project Name**: vue-testing-library - **Description**: 🦎 Simple and complete Vue.js testing utilities that encourage good testing practices. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-01-05 - **Last Updated**: 2026-03-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
Simple and complete Vue.js testing utilities that encourage good testing practices.
Vue Testing Library is a lightweight adapter built on top of DOM Testing Library and @vue/test-utils.
Times clicked: {{ count }}
``` ```js import {render, screen, fireEvent} from '@testing-library/vue' import Button from './Button' test('increments value on click', async () => { // The `render` method renders the component into the document. // It also binds to `screen` all the available queries to interact with // the component. render(Button) // queryByText returns the first matching node for the provided text // or returns null. expect(screen.queryByText('Times clicked: 0')).toBeTruthy() // getByText returns the first matching node for the provided text // or throws an error. const button = screen.getByText('increment') // Click a couple of times. await fireEvent.click(button) await fireEvent.click(button) expect(screen.queryByText('Times clicked: 2')).toBeTruthy() }) ``` > You might want to install [`jest-dom`][jest-dom] to add handy assertions such > as `.toBeInTheDocument()`. In the example above, you could write > `expect(screen.getByText('Times clicked: 0')).toBeInTheDocument()`. > Using `byText` queries it's not the only nor the best way to query for > elements. Read [Which query should I use?][which-query] to discover > alternatives. In the example above, `getByRole('button', {name: 'increment'})` > is possibly the best option to get the button element. ### More examples You'll find examples of testing with different situations and popular libraries in [the test directory][test-directory]. Some included are: - [`vuex`][vuex-example] - [`vue-router`][vue-router-example] - [`vee-validate`][vee-validate-example] - [`vue-i18n`][vue-i18n-example] - [`vuetify`][vuetify-example] Feel free to contribute with more examples! ## Guiding Principles > [The more your tests resemble the way your software is used, the more > confidence they can give you.][guiding-principle] We try to only expose methods and utilities that encourage you to write tests that closely resemble how your Vue components are used. Utilities are included in this project based on the following guiding principles: 1. If it relates to rendering components, it deals with DOM nodes rather than component instances, nor should it encourage dealing with component instances. 2. It should be generally useful for testing individual Vue components or full Vue applications. 3. Utility implementations and APIs should be simple and flexible. At the end of the day, what we want is for this library to be pretty light-weight, simple, and understandable. ## Docs [**Read the docs**][docs] | [Edit the docs][docs-edit] ## Typings _Please note that TypeScript 4.X is required._ The TypeScript type definitions are in the [types][types-directory] directory. ## ESLint support If you want to lint test files that use Vue Testing Library, you can use the official plugin: [eslint-plugin-testing-library][eslint-plugin-testing-library]. ## Issues _Looking to contribute? Look for the [Good First Issue][good-first-issue] label._ ### 🐛 Bugs Please [file an issue][add-issue-bug] for bugs, missing documentation, or unexpected behavior. [**See Bugs**][bugs] ### 💡 Feature Requests Please [file an issue][add-issue] to suggest new features. Vote on feature requests by adding a 👍. This helps maintainers prioritize what to work on. ### ❓ Questions For questions related to using the library, please visit a support community instead of filing an issue on GitHub. - [Discord][discord] ## License [MIT][license] ## Contributors [](https://github.com/dfcook) [](https://github.com/afontcu) [](https://github.com/eunjae-lee) [](https://github.com/tim-maguire) [](https://github.com/samdelacruz) [](https://github.com/ankitsinghaniyaz) [](https://github.com/lindgr3n) [](https://github.com/kentcdodds) [](https://github.com/brennj) [](https://github.com/makeupsomething) [](https://github.com/mb200) [](https://github.com/Oluwasetemi) [](https://github.com/cimbul) [](https://github.com/alexkrolick) [](https://github.com/edufarre) [](https://github.com/SandraDml) [](https://github.com/arnaublanche) [](https://github.com/NoelDeMartin) [](https://github.com/chiptus) [](https://github.com/bennettdams) [](https://github.com/mediafreakch) [](https://github.com/afenton90) [](https://github.com/cilice) [](https://github.com/ITenthusiasm) [coverage-badge]: https://img.shields.io/codecov/c/github/testing-library/vue-testing-library.svg [coverage]: https://codecov.io/github/testing-library/vue-testing-library [github-badge]: https://badge.fury.io/gh/testing-library%2Fvue-testing-library.svg [github]: https://badge.fury.io/gh/testing-library%2Fvue-testing-library [npm-badge]: https://badge.fury.io/js/%40testing-library%2Fvue.svg [npm]: https://badge.fury.io/js/%40testing-library%2Fvue [license-badge]: https://img.shields.io/github/license/testing-library/vue-testing-library.svg [license]: https://github.com/testing-library/vue-testing-library/blob/master/LICENSE [discord]: https://testing-library.com/discord [discord-badge]: https://img.shields.io/discord/723559267868737556.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2&style=flat-square [jest-dom]: https://github.com/testing-library/jest-dom [which-query]: https://testing-library.com/docs/guide-which-query [guiding-principle]: https://twitter.com/kentcdodds/status/977018512689455106 [good-first-issue]: https://github.com/testing-library/vue-testing-library/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22 [docs]: https://testing-library.com/vue [docs-edit]: https://github.com/testing-library/testing-library-docs [eslint-plugin-testing-library]: https://github.com/testing-library/eslint-plugin-testing-library [bugs]: https://github.com/testing-library/vue-testing-library/issues?q=is%3Aissue+is%3Aopen+label%3Abug+sort%3Acreated-desc [add-issue-bug]: https://github.com/testing-library/vue-testing-library/issues/new?assignees=&labels=bug&template=bug_report.md&title= [add-issue]: (https://github.com/testing-library/vue-testing-library/issues/new) [types-directory]: https://github.com/testing-library/vue-testing-library/blob/main/types [test-directory]: https://github.com/testing-library/vue-testing-library/blob/main/src/__tests__ [vuex-example]: https://github.com/testing-library/vue-testing-library/blob/main/src/__tests__/vuex.js [vue-router-example]: https://github.com/testing-library/vue-testing-library/blob/main/src/__tests__/vue-router.js [vee-validate-example]: https://github.com/testing-library/vue-testing-library/blob/main/src/__tests__/validate-plugin.js [vue-i18n-example]: https://github.com/testing-library/vue-testing-library/blob/main/src/__tests__/translations-vue-i18n.js [vuetify-example]: https://github.com/testing-library/vue-testing-library/blob/main/src/__tests__/vuetify.js