先後於台中 Microprogram 微程式資訊 與 Newegg 台灣新蛋 擔任前端工程師,負責使用前端技術開發與維護 Web 與 React Native App 相關服務。
現任職於 Storipress 擔任前端工程師,除了前端功能的開發以外,在團隊中也負責前端專案 DevOps 優化的工作。
主要出沒地:
不論人工測試或自動化測試
如此高頻率的測試
手動測試無法涵蓋所有情境
測試的目的在防止已知的問題再次出現
function addDecimal(text?: string | number | null) {
if (Number.isNaN(Number(text))) return '0.00'
if (typeof text === 'number' || /\d+\.\d+/.test(String(text))) {
text = Number(text).toFixed(2)
}
return Number(`${text ?? 0}`.replace(/\B(?=\d{2}$)/, '.'))
.toFixed(2)
.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}
test('addDecimal', () => {
expect(addDecimal()).toBe('0.00')
expect(addDecimal(null)).toBe('0.00')
expect(addDecimal('abc')).toBe('0.00')
expect(addDecimal('0')).toBe('0.00')
expect(addDecimal('1')).toBe('1.00')
expect(addDecimal('12')).toBe('12.00')
expect(addDecimal('12345')).toBe('123.45')
expect(addDecimal('123451')).toBe('1,234.51')
expect(addDecimal('123.45')).toBe('123.45')
expect(addDecimal('123.451')).toBe('123.45')
expect(addDecimal(12345)).toBe('12,345.00')
expect(addDecimal(123456)).toBe('123,456.00')
expect(addDecimal(123.45)).toBe('123.45')
expect(addDecimal(123.451)).toBe('123.45')
expect(addDecimal(0)).toBe('0.00')
})
分享我們團隊 (新創團隊) 的協作流程:
Jest 是前端單元測試主流的測試框架之一,提供測試覆蓋率報告、快照測試等方便的功能
Vitest 提供了與 Jest 兼容的 API
從比較簡單的純 function 的測試開始
一個測試檔案可能會有像這樣的架構
最常見的基本 Matcher
也有透過 Snapshot 來檢查的方式
測試不一定要完整的寫完測試案例: toMatchSnapshot
以接近真實的使用方式來進行測試
不去關注組件內部的狀態,重點關注在呈現結果
組件測試的第一步
Single Element
Type of Query | 0 Matches | 1 Match | >1 Matches | Retry (Async/Await) |
---|---|---|---|---|
getBy… | Throw error | Return element | Throw error | No |
queryBy… | Return null | Return element | Throw error | No |
findBy… | Throw error | Return element | Throw error | Yes |
Multiple Elements
Type of Query | 0 Matches | 1 Match | >1 Matches | Retry (Async/Await) |
---|---|---|---|---|
getAllBy… | Throw error | Return array | Return array | No |
queryAllBy… | Return [] | Return array | Return array | No |
findAllBy… | Throw error | Return array | Return array | Yes |
需要對 HTML aria 有一定程度的理解
可參閱相關文件 HTML aria #docconformance
Query 的工具
@testing-library/user-event
User Interactions
test('userEvent example', () => {
const input = screen.getByRole('textbox')
userEvent.type(input, 'Hello, World!')
expect(input).toHaveValue('Hello, World!')
})
test('fireEvent example', () => {
const input = screen.getByRole('textbox')
fireEvent.change(input, { target: { value: 'Hello, World!' } })
expect(input).toHaveValue('Hello, World!')
})
reactjs-vite-tailwindcss-boilerplate - React Tailwindcss Boilerplate build with Vite
This is a boilerplate build with Vite, React 18, TypeScript, Vitest, Testing Library, TailwindCSS 3, Eslint and Prettier.
Mock Service Worker
// mocks/restful/unsplash.js
import { rest } from 'msw'
import data from './unsplash.json'
export const handler = rest
.get(
'https://api.unsplash.com/photos',
(req, res, ctx) => res(ctx.json(data))
)
Testing Library Demo - CodeSandbox
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing