Skip to content

Instantly share code, notes, and snippets.

@ytyubox
Created May 18, 2019 10:07
Show Gist options
  • Save ytyubox/77071afa012bf87ec6fcfb0c15c355a1 to your computer and use it in GitHub Desktop.
Save ytyubox/77071afa012bf87ec6fcfb0c15c355a1 to your computer and use it in GitHub Desktop.
Share note on the day of May 16, 2019, host by Howard at GoodIdeas Studio, Tainan.
title tags
透過 Jest 快速測試 API,不用燃燒生命幫後端 debug
Howard, test, jest, API

透過 Jest 快速測試 API,不用燃燒生命幫後端 debug

後端 API 測試責任 前端手動測試 前端遲早要自己測試 API 的!


Snapshot Test vs. Schema Test

snap test

save result into history 每次執行會產出一個 .snap 檔名的 Snapshot 檔案。 記得 git 去追蹤每次測試的結果差異。

let result = (input = output) ?  success : error
  1. mc testing
  2. jest init
  3. jest.config.js
testMatch:[
"REGEX.FILE"
]
  1. snapshot.js

  1. npm test
  2. .toMatchSnapshot()
  3. fix snapshot by rm
# fail case
- Snapshot
+ received

schema test

schema 像是描述器,敘述規則與格式,用來比對測試結果。 jest json schema

test('schema test')

iOS codable Unit test

QA: if BE change a lot?

A: make a CI for BE


JSON SCHEMA TOOL

https://jsonschema.net/

  • 左上角的 Menubar 修改 Configuration,可以將 Global > URI Format 改成 none 再產出,比較不會帶有的沒的。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment