|
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} |
6 | 29 |
|
@@ -40,7 +63,7 @@ Vue アプリケーションのテスト戦略を設計する際には、以下 |
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 @@ Vue アプリケーションでは、コンポーネントは UI の主要な構 |
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') // // コンポーネント内に "0 "があることを暗黙のうちに評価します |
| 204 | +getByText('0') // // コンポーネント内に "0 "があることを暗黙のうちに評価します |
178 | 205 |
|
179 | | - const button = getByRole('button', { name: /increment/i }) |
| 206 | +const button = getByRole('button', { name: /increment/i }) |
180 | 207 |
|
181 | | - // インクリメントボタンにクリックイベントをディスパッチします。 |
182 | | - await fireEvent.click(button) |
| 208 | +// インクリメントボタンにクリックイベントをディスパッチします。 |
| 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> |
@@ -265,6 +292,16 @@ Vitest とブラウザーベースのランナーの主な違いは、スピー |
265 | 292 |
|
266 | 293 | - [Cypress](https://www.cypress.io/) は、情報豊富なグラフィカルインターフェース、優れたデバッグ性、組み込みアサーションとスタブ、耐フレーク性(flake-resistance)、スナップショットなどの機能を備えています。また、前述の通り[コンポーネントテスト](https://docs.cypress.io/guides/component-testing/introduction)もサポートしています。Chromium ベースのブラウザー、Firefox、Electron をサポートしています。WebKit のサポートもありますが、実験的機能とされています。Cypress は MIT ライセンスですが、並列化などの一部の機能には 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 は、AI 支援によるテスト生成機能を備え、主要なブラウザと実機を対象に、E2E、アクセシビリティ、Visual Regression Test を実行するためのクラウドプラットフォームです!</div> |
| 301 | + </div> |
| 302 | + </a> |
| 303 | +</div> |
| 304 | + |
268 | 305 | ### その他の選択肢 {#other-options-2} |
269 | 306 |
|
270 | 307 | - [Nightwatch](https://nightwatchjs.org/) は、[Selenium WebDriver](https://www.npmjs.com/package/selenium-webdriver) をベースとした E2E テストソリューションです。こちらはネイティブモバイルテストを含む、最も広い範囲のブラウザーをサポートしています。Selenium ベースのソリューションは、Playwright や Cypress よりも遅くなります。 |
|
0 commit comments