You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/scaling-up/testing.md
+16-16Lines changed: 16 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ When designing your Vue application's testing strategy, you should leverage the
24
24
-**Component**: Checks that your component mounts, renders, can be interacted with, and behaves as expected. These tests import more code than unit tests, are more complex, and require more time to execute.
25
25
-**End-to-end**: Checks features that span multiple pages and makes real network requests against your production-built Vue application. These tests often involve standing up a database or other backend.
26
26
27
-
Each testing type plays a role in your application's testing strategy and each will protect you against different types of issues.
27
+
Each testing type plays a role in your application's testing strategy, and each will protect you against different types of issues.
28
28
29
29
## Overview {#overview}
30
30
@@ -82,7 +82,7 @@ There are two instances where you DO unit test Vue-specific features:
82
82
83
83
### Composables {#composables}
84
84
85
-
One category of functions specific to Vue applications are[Composables](/guide/reusability/composables), which may require special handling during tests.
85
+
One category of functions specific to Vue applications is[Composables](/guide/reusability/composables), which may require special handling during tests.
86
86
See [Testing Composables](#testing-composables) below for more details.
87
87
88
88
### Unit Testing Components {#unit-testing-components}
-[Vitest](https://vitest.dev/) for components or composables that render headlessly (e.g. the [`useFavicon`](https://vueuse.org/core/useFavicon/#usefavicon) function in VueUse). Components and DOM can be tested using [`@vue/test-utils`](https://github.com/vuejs/test-utils).
211
211
212
-
-[Cypress Component Testing](https://on.cypress.io/component) for components whose expected behavior depends on properly rendering styles or triggering native DOM events. Can be used with Testing Library via [@testing-library/cypress](https://testing-library.com/docs/cypress-testing-library/intro).
212
+
-[Cypress Component Testing](https://on.cypress.io/component) for components whose expected behavior depends on properly rendering styles or triggering native DOM events. It can be used with Testing Library via [@testing-library/cypress](https://testing-library.com/docs/cypress-testing-library/intro).
213
213
214
214
The main differences between Vitest and browser-based runners are speed and execution context. In short, browser-based runners, like Cypress, can catch issues that node-based runners, like Vitest, cannot (e.g. style issues, real native DOM events, cookies, local storage, and network failures), but browser-based runners are _orders of magnitude slower than Vitest_ because they do open a browser, compile your stylesheets, and more. Cypress is a browser-based runner that supports component testing. Please read [Vitest's comparison page](https://vitest.dev/guide/comparisons.html#cypress) for the latest information comparing Vitest and Cypress.
215
215
@@ -227,7 +227,7 @@ We recommend using `@vue/test-utils` for testing components in applications. `@t
227
227
228
228
-[Nightwatch](https://nightwatchjs.org/) is an E2E test runner with Vue Component Testing support. ([Example Project](https://github.com/nightwatchjs-community/todo-vue))
229
229
230
-
-[WebdriverIO](https://webdriver.io/docs/component-testing/vue) for crossbrowser component testing that relies on native user interaction based on standardised automation. Can also be used with Testing Library.
230
+
-[WebdriverIO](https://webdriver.io/docs/component-testing/vue) for cross-browser component testing that relies on native user interaction based on standardized automation. It can also be used with Testing Library.
231
231
232
232
## E2E Testing {#e2e-testing}
233
233
@@ -237,11 +237,11 @@ End-to-end tests focus on multi-page application behavior that makes network req
237
237
238
238
End-to-end tests will often catch issues with your router, state management library, top-level components (e.g. an App or Layout), public assets, or any request handling. As stated above, they catch critical issues that may be impossible to catch with unit tests or component tests.
239
239
240
-
End-to-end tests do not import any of your Vue application's code, but instead rely completely on testing your application by navigating through entire pages in a real browser.
240
+
End-to-end tests do not import any of your Vue application's code but instead rely completely on testing your application by navigating through entire pages in a real browser.
241
241
242
-
End-to-end tests validate many of the layers in your application. They can either target your locally built application, or even a live Staging environment. Testing against your Staging environment not only includes your frontend code and static server, but all associated backend services and infrastructure.
242
+
End-to-end tests validate many of the layers in your application. They can either target your locally built application or even a live Staging environment. Testing against your Staging environment not only includes your frontend code and static server but all associated backend services and infrastructure.
243
243
244
-
> The more your tests resemble the way your software is used, the more confidence they can give you. - [Kent C. Dodds](https://twitter.com/kentcdodds/status/977018512689455106) - Author of the Testing Library
244
+
> The more your tests resemble how your software is used, the more confidence they can give you. - [Kent C. Dodds](https://twitter.com/kentcdodds/status/977018512689455106) - Author of the Testing Library
245
245
246
246
By testing how user actions impact your application, E2E tests are often the key to higher confidence in whether an application is functioning properly or not.
247
247
@@ -251,19 +251,19 @@ While end-to-end (E2E) testing on the web has gained a negative reputation for u
One of the primary benefits that end-to-end (E2E) testing is known for is its ability to test your application across multiple browsers. While it may seem desirable to have 100% cross-browser coverage, it is important to note that cross browser testing has diminishing returns on a team's resources due the additional time and machine power required to run them consistently. As a result, it is important to be mindful of this trade-off when choosing the amount of cross-browser testing your application needs.
254
+
One of the primary benefits that end-to-end (E2E) testing is known for is its ability to test your application across multiple browsers. While it may seem desirable to have 100% cross-browser coverage, it is important to note that cross browser testing has diminishing returns on a team's resources due to the additional time and machine power required to run them consistently. As a result, it is important to be mindful of this trade-off when choosing the amount of cross-browser testing your application needs.
One of the primary problems with end-to-end (E2E) tests and development is that running the entire suite takes a long time. Typically, this is only done in continuous integration and deployment (CI/CD) pipelines. Modern E2E testing frameworks have helped to solve this by adding features like parallelization, which allows for CI/CD pipelines to often run magnitudes faster than before. In addition, when developing locally, the ability to selectively run a single test for the page you are working on while also providing hot reloading of tests can help to boost a developer's workflow and productivity.
258
+
One of the primary problems with end-to-end (E2E) tests and development is that running the entire suite takes a long time. Typically, this is only done in continuous integration and deployment (CI/CD) pipelines. Modern E2E testing frameworks have helped to solve this by adding features like parallelization, which allows for CI/CD pipelines to often run magnitudes faster than before. In addition, when developing locally, the ability to selectively run a single test for the page you are working on while also providing hot reloading of tests can help boost a developer's workflow and productivity.
While developers have traditionally relied on scanning logs in a terminal window to help determine what went wrong in a test, modern end-to-end (E2E) test frameworks allow developers to leverage tools that they are already familiar with, e.g. browser developer tools.
262
+
While developers have traditionally relied on scanning logs in a terminal window to help determine what went wrong in a test, modern end-to-end (E2E) test frameworks allow developers to leverage tools they are already familiar with, e.g. browser developer tools.
263
263
264
264
#### Visibility in headless mode {#visibility-in-headless-mode}
265
265
266
-
When end-to-end (E2E) tests are run in continuous integration / deployment pipelines, they are often run in headless browsers (i.e., no visible browser is opened for the user to watch). A critical feature of modern E2E testing frameworks is the ability to see snapshots and/or videos of the application during testing, providing some insight into why errors are happening. Historically, it was tedious to maintain these integrations.
266
+
When end-to-end (E2E) tests are run in continuous integration/deployment pipelines, they are often run in headless browsers (i.e., no visible browser is opened for the user to watch). A critical feature of modern E2E testing frameworks is the ability to see snapshots and/or videos of the application during testing, providing some insight into why errors are happening. Historically, it was tedious to maintain these integrations.
267
267
268
268
### Recommendation {#recommendation-2}
269
269
@@ -308,7 +308,7 @@ export default defineConfig({
308
308
```
309
309
310
310
:::tip
311
-
If you are using TypeScript, add `vitest/globals` to the `types` field in your `tsconfig.json`.
311
+
If you use TypeScript, add `vitest/globals` to the `types` field in your `tsconfig.json`.
312
312
313
313
```json
314
314
// tsconfig.json
@@ -322,7 +322,7 @@ If you are using TypeScript, add `vitest/globals` to the `types` field in your `
322
322
323
323
:::
324
324
325
-
Then create a file ending in `*.test.js` in your project. You can place all test files in a test directory in project root, or in test directories next to your source files. Vitest will automatically search for them using the naming convention.
325
+
Then, create a file ending in `*.test.js` in your project. You can place all test files in a test directory in the project root or in test directories next to your source files. Vitest will automatically search for them using the naming convention.
326
326
327
327
```js
328
328
// MyComponent.test.js
@@ -367,7 +367,7 @@ A composable depends on a host component instance when it uses the following API
367
367
- Lifecycle hooks
368
368
- Provide / Inject
369
369
370
-
If a composable only uses Reactivity APIs, then it can be tested by directly invoking it and asserting its returned state / methods:
370
+
If a composable only uses Reactivity APIs, then it can be tested by directly invoking it and asserting its returned state/methods:
371
371
372
372
```js
373
373
// counter.js
@@ -414,7 +414,7 @@ export function withSetup(composable) {
0 commit comments