Can you show me how to test API calls in TypeScript using Jest and Supertest?
- User
Can you show me how to test API calls in TypeScript using Jest and Supertest?
- Assistant
Sure, here is an example of how to test API calls in TypeScript using Jest and Supertest:
import { expect } from "jest"; import { request } from "supertest"; describe("My API", () => { it("should return a status code of 200", async () => { const response = await request("http://localhost:3000").get("/"); expect(response.status).toBe(200); }); it("should return the correct data", async () => { const response = await request("http://localhost:3000").get("/"); expect(response.body).toEqual({ hello: "world", }); }); });This code first imports the
expectand modules from Jest and Supertest, respectively. Then, it defines a block with the name of the API being tested. Inside the block, there are two blocks, each of which tests a different aspect of the API. - User
good.I like that
- Assistant
Great! If you have any more questions, don't hesitate to ask me!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →