Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
JSDC2020 - 用 API mocking 讓前端不再苦等待
Search
Huli
October 17, 2020
Programming
1.5k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JSDC2020 - 用 API mocking 讓前端不再苦等待
https://github.com/aszx87410/api-mocking-demo-app
簡單介紹 MSW 與 MirageJS
Huli
October 17, 2020
More Decks by Huli
See All by Huli
從冷知識到漏洞,你不懂的 Web,駭客懂 - Huli @ WebConf Taiwan 2025
aszx87410
4
4.4k
ModernWeb 2018 - 輕鬆應付複雜的非同步操作:RxJS + Redux Observable
aszx87410
0
330
Attacking web without JS - CSS injection
aszx87410
0
3.5k
Front-end Security that Front-end developers don't know
aszx87410
2
6k
你懂了 JavaScript,也不懂 JavaScript - MOPCON 2021
aszx87410
3
1.4k
接觸資安才發現前端的水真深 - Modern Web 2021
aszx87410
0
2.7k
Other Decks in Programming
See All in Programming
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
190
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
150
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
220
Performance Optimization With LLMs
xleitix
0
240
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
320
Kotlinize Is Not Just Converting to Kotlin
chigichan24
1
220
Crash Auto Pipelines
veronikapj
1
350
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
250
DroidKnights 2026 Android A2UI Jetpack Compose 기반의 안전한 AI UI 렌더링 - 박제창
itsmedreamwalker
1
160
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
130
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
230
GraphQL の onError と Nullability のこれから
quramy
0
210
Featured
See All Featured
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
600
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.4k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
43k
Making Projects Easy
brettharned
120
6.8k
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
520
Deep Space Network (abreviated)
tonyrice
0
410
Practical Orchestrator
shlominoach
192
12k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
320
The SEO Collaboration Effect
kristinabergwall1
1
620
Transcript
⽤用 API mocking 讓前 端不再苦苦等待 huli
[email protected]
https://blog.huli.tw OneDegree 資深前端⼯工程師
前端 後端 API User
前端 後端 API User
前端 後端 API User 「我要等後端好才能開始接喔」
該怎麼處理理這個狀狀況?
如果後端連 interface 都還沒定好...
http://www.quickmeme.com/meme/3rwr8s
None
幾個⽅方法 • 不管,繼續等待後端
幾個⽅方法 • 不管,繼續等待後端 • Express ⾃自⼰己弄弄
幾個⽅方法 • 不管,繼續等待後端 • Express ⾃自⼰己弄弄 • JSON server 假資料
幾個⽅方法 • 不管,繼續等待後端 • Express ⾃自⼰己弄弄 • JSON server 假資料
• MSW • MirageJS
None
None
登入⾴頁⾯面 後台⾴頁⾯面 是否有 token 是 POST /login 成功之後把 token 寫進
localStorage 並導到後台 否,輸入帳號密碼
登入⾴頁⾯面 確認 localStorage 後台⾴頁⾯面 GET /me 登入⾴頁⾯面 沒 token 有
token 失敗 是否有 token 是 POST /login 成功之後把 token 寫進 localStorage 並導到後台 否,輸入帳號密碼 清除 localStorage
MSW Mock Service Worker
None
前端網站 API Server
前端網站 Service Worker API Server 瀏覽器
設定步驟 • 加上 service worker • 加上 handler
None
None
None
None
還可以針對各種狀狀況 寫測試!
None
None
None
Mirage JS
None
前端網站 API Server
前端網站 fetch XHR API Server JavaScript
None
None
None
寫測試? 當然沒問題
None
None
mirage 的強項
None
None
None
None
總結 cy.route msw mirage 使⽤用在開發上 X O O 使⽤用在測試上 O
O O 特⾊色 cypress 內建 使⽤用 service worker 打造出完整的 mock api 缺點 只能⽤用在測試 設置較⿇麻煩 適合放靜態資料 需要較多時間
https://github.com/aszx87410/api- mocking-demo-app