React Mock
Mocking api calls from React Applications, using Pretenderjs and Fakerjs.
Simple Example usage
const endPoint = '/api/v1/todos' const todoSchema = author: Fakerinternet Fakerlorem Fakerdate const requestHandler = { const todoList = generatornext10 todoSchema; return 200 'Content-Type': 'application/json' JSON;} ServerServer // to start mocking /api/v1/todos API
axios
Real use case
- Suppose you want to simulate the fetching of 10 guides
- You know the API Endpoint
- You know the Format of each guide object
- You know the Format of the Error response
// <app-root>/src/mock-server const apiRoute = '/api/v1/guides'const requestHandler = { const guides = generatornext10; // @returns { <id1>: schema1, <id2>: schema2 } // const error = generator.error(); return 200 'Content-Type': 'application/json' JSON;} const schema = description: Fakerlorem createdAt: Fakerdate favoredCount: Fakerrandom isPublic: random author: id: uidnext name: Fakername picture: Fakerinternet ; const errorFormat = message: Fakerlorem Server Server // @returns Promise that resolves with null or rejects with Error// Server.off()