웹 API 목 객체
// 웹 API 클라이언트
export type Profile = {
id : string
name ?: string
age ?: number
email : string
}
export function getMyProfile() : Promise<Profile> {
return fetch('https://myapi.testing.com/my/profile').then(async (res) => {
const data = await res.json()
if ( !res.ok ) {
throw data
}
return data
})
}import { getMyProfile } from '../fetchers'
export async function getGreet() {
const data = await getMyProfile()
if(!data.name) {
return `안녕!`
}
return `안녕 ${data.name}`
}웹 API 클라이언트 스텁
데이터 취득 성공을 재현한 테스트
데이터 취득 실패를 재현한 테스트
예외 검증 테스트 코드
Last updated