測試(前端)
テストの学習へようこそ!  |  web.dev
2021-06-03 The Testing Trophy and Testing Classifications
2023-07-13 webフロントエンドテストと自動化 - Speaker Deck
測試範圍
1. 靜態測試
2. 單元測試
3. 整合測試
4. 端對端測試
測試金字塔
範圍越大,則開發、執行成本和不穩定度也會越高
テストピラミッド万歳 | POSTD
測試獎盃模型
更重視使用者視點的想法
視覺回歸測試
a11y測試
常用工具
靜態測試
ESLint、TypeScript
單元測試
Jest、Vitest
整合測試
Testing Library、jest-dom
端對端測試
Cypress、Playwright
視覺回歸測試
Chromatic(Storybook)、reg-suite
整合測試範例
Testing Library + Jest
1. 取得元素
const addButton = await screen.findByRole('button');
get | find | query
All | (x)
By + Role | LabelText | PlaceholderText | Text | DisplayValue | AltText | Title | TestId
應該優先的元素
WAI-ARIA Roles
label
placeholder
text
2. 進行操作
userEvent.click([元素])
userEvent.type([元素], "輸入文字")
3. 驗證結果
元素是否存在
const addButton = await screen.findByRole('button', { name: '新增' });
元素是否消失
code:javascript
const addButton = await screen.findByRole('button', { name: '新增' });
expect(addButton).toBeNull();
元素數量是否正確
code:javascript
const addButton = await screen.findByRole('listItem',);
expect(nameList.length).toBe(3);
連線測試
mock service worker
API Mocking
工具
Selenium
Jest
Nightwatch
Nightwatch V3 | Node.js powered End-to-End testing framework
Puppeteer
SafeTest
2024-02-25 新しい UI テストの手法を提供するテストライブラリ SafeTest
測試
前端