|
1 | 1 | <script setup>
|
2 | 2 | import { VTCodeGroup, VTCodeGroupTab } from '@vue/theme'
|
3 | 3 | </script>
|
| 4 | +<style> |
| 5 | +.lambdatest { |
| 6 | + background-color: var(--vt-c-bg-soft); |
| 7 | + border-radius: 8px; |
| 8 | + padding: 12px 16px 12px 12px; |
| 9 | + font-size: 13px; |
| 10 | + a { |
| 11 | + display: flex; |
| 12 | + color: var(--vt-c-text-2); |
| 13 | + } |
| 14 | + img { |
| 15 | + background-color: #fff; |
| 16 | + padding: 12px 16px; |
| 17 | + border-radius: 6px; |
| 18 | + margin-right: 24px; |
| 19 | + } |
| 20 | + .testing-partner { |
| 21 | + color: var(--vt-c-text-1); |
| 22 | + font-size: 15px; |
| 23 | + font-weight: 600; |
| 24 | + } |
| 25 | +} |
| 26 | +</style> |
4 | 27 |
|
5 | 28 | # Testing {#testing}
|
6 | 29 |
|
@@ -40,7 +63,7 @@ Take for example this `increment` function:
|
40 | 63 |
|
41 | 64 | ```js
|
42 | 65 | // helpers.js
|
43 |
| -export function increment (current, max = 10) { |
| 66 | +export function increment(current, max = 10) { |
44 | 67 | if (current < max) {
|
45 | 68 | return current + 1
|
46 | 69 | }
|
@@ -129,62 +152,66 @@ Component tests should focus on the component's public interfaces rather than in
|
129 | 152 | <VTCodeGroup>
|
130 | 153 | <VTCodeGroupTab label="Vue Test Utils">
|
131 | 154 |
|
132 |
| - ```js |
133 |
| - const valueSelector = '[data-testid=stepper-value]' |
134 |
| - const buttonSelector = '[data-testid=increment]' |
| 155 | +```js |
| 156 | +const valueSelector = '[data-testid=stepper-value]' |
| 157 | +const buttonSelector = '[data-testid=increment]' |
135 | 158 |
|
136 |
| - const wrapper = mount(Stepper, { |
137 |
| - props: { |
138 |
| - max: 1 |
139 |
| - } |
140 |
| - }) |
| 159 | +const wrapper = mount(Stepper, { |
| 160 | + props: { |
| 161 | + max: 1 |
| 162 | + } |
| 163 | +}) |
141 | 164 |
|
142 |
| - expect(wrapper.find(valueSelector).text()).toContain('0') |
| 165 | +expect(wrapper.find(valueSelector).text()).toContain('0') |
143 | 166 |
|
144 |
| - await wrapper.find(buttonSelector).trigger('click') |
| 167 | +await wrapper.find(buttonSelector).trigger('click') |
145 | 168 |
|
146 |
| - expect(wrapper.find(valueSelector).text()).toContain('1') |
147 |
| - ``` |
| 169 | +expect(wrapper.find(valueSelector).text()).toContain('1') |
| 170 | +``` |
148 | 171 |
|
149 | 172 | </VTCodeGroupTab>
|
150 | 173 | <VTCodeGroupTab label="Cypress">
|
151 | 174 |
|
152 |
| - ```js |
153 |
| - const valueSelector = '[data-testid=stepper-value]' |
154 |
| - const buttonSelector = '[data-testid=increment]' |
| 175 | +```js |
| 176 | +const valueSelector = '[data-testid=stepper-value]' |
| 177 | +const buttonSelector = '[data-testid=increment]' |
155 | 178 |
|
156 |
| - mount(Stepper, { |
157 |
| - props: { |
158 |
| - max: 1 |
159 |
| - } |
160 |
| - }) |
| 179 | +mount(Stepper, { |
| 180 | + props: { |
| 181 | + max: 1 |
| 182 | + } |
| 183 | +}) |
161 | 184 |
|
162 |
| - cy.get(valueSelector).should('be.visible').and('contain.text', '0') |
163 |
| - .get(buttonSelector).click() |
164 |
| - .get(valueSelector).should('contain.text', '1') |
165 |
| - ``` |
| 185 | +cy.get(valueSelector) |
| 186 | + .should('be.visible') |
| 187 | + .and('contain.text', '0') |
| 188 | + .get(buttonSelector) |
| 189 | + .click() |
| 190 | + .get(valueSelector) |
| 191 | + .should('contain.text', '1') |
| 192 | +``` |
166 | 193 |
|
167 | 194 | </VTCodeGroupTab>
|
168 | 195 | <VTCodeGroupTab label="Testing Library">
|
169 | 196 |
|
170 |
| - ```js |
171 |
| - const { getByText } = render(Stepper, { |
172 |
| - props: { |
173 |
| - max: 1 |
174 |
| - } |
175 |
| - }) |
| 197 | +```js |
| 198 | +const { getByText } = render(Stepper, { |
| 199 | + props: { |
| 200 | + max: 1 |
| 201 | + } |
| 202 | +}) |
176 | 203 |
|
177 |
| - getByText('0') // Implicit assertion that "0" is within the component |
| 204 | +getByText('0') // Implicit assertion that "0" is within the component |
178 | 205 |
|
179 |
| - const button = getByRole('button', { name: /increment/i }) |
| 206 | +const button = getByRole('button', { name: /increment/i }) |
180 | 207 |
|
181 |
| - // Dispatch a click event to our increment button. |
182 |
| - await fireEvent.click(button) |
| 208 | +// Dispatch a click event to our increment button. |
| 209 | +await fireEvent.click(button) |
183 | 210 |
|
184 |
| - getByText('1') |
| 211 | +getByText('1') |
185 | 212 |
|
186 |
| - await fireEvent.click(button) |
187 |
| - ``` |
| 213 | +await fireEvent.click(button) |
| 214 | +``` |
188 | 215 |
|
189 | 216 | </VTCodeGroupTab>
|
190 | 217 | </VTCodeGroup>
|
@@ -221,7 +248,7 @@ We recommend using `@vue/test-utils` for testing components in applications. `@t
|
221 | 248 |
|
222 | 249 | - [Nightwatch](https://nightwatchjs.org/) is an E2E test runner with Vue Component Testing support. ([Example Project](https://github.com/nightwatchjs-community/todo-vue))
|
223 | 250 |
|
224 |
| -- [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. |
| 251 | +- [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. |
225 | 252 |
|
226 | 253 | ## E2E Testing {#e2e-testing}
|
227 | 254 |
|
@@ -265,6 +292,16 @@ When end-to-end (E2E) tests are run in continuous integration/deployment pipelin
|
265 | 292 |
|
266 | 293 | - [Cypress](https://www.cypress.io/) has an informative graphical interface, excellent debuggability, built-in assertions, stubs, flake-resistance, and snapshots. As mentioned above, it provides stable support for [Component Testing](https://docs.cypress.io/guides/component-testing/introduction). Cypress supports Chromium-based browsers, Firefox, and Electron. WebKit support is available, but marked experimental. Cypress is MIT-licensed, but some features like parallelization require a subscription to Cypress Cloud.
|
267 | 294 |
|
| 295 | +<div class="lambdatest"> |
| 296 | + <a href="https://lambdatest.com" target="_blank"> |
| 297 | + <img src="/images/lambdatest.svg"> |
| 298 | + <div> |
| 299 | + <div class="testing-partner">Testing Sponsor</div> |
| 300 | + <div>Lambdatest is a cloud platform for running E2E, accessibility, and visual regression tests across all major browsers and real devices, with AI assisted test generation!</div> |
| 301 | + </div> |
| 302 | + </a> |
| 303 | +</div> |
| 304 | + |
268 | 305 | ### Other Options {#other-options-2}
|
269 | 306 |
|
270 | 307 | - [Nightwatch](https://nightwatchjs.org/) is an E2E testing solution based on [Selenium WebDriver](https://www.npmjs.com/package/selenium-webdriver). This gives it the widest browser support range, including native mobile testing. Selenium-based solutions will be slower than Playwright or Cypress.
|
|
0 commit comments