Skip to content

Instantly share code, notes, and snippets.

@up1
Last active July 29, 2026 14:44
Show Gist options
  • Select an option

  • Save up1/28e012b3cdc99ab3ad249fcd62fa4b3a to your computer and use it in GitHub Desktop.

Select an option

Save up1/28e012b3cdc99ab3ad249fcd62fa4b3a to your computer and use it in GitHub Desktop.
NodeJS :: Good testing
beforeAll(async () => {
await seedDatabase();
});
describe("GET /users", () => {
test("user exists", async () => {
...
});
test("update user", async () => {
...
});
test("delete user", async () => {
...
});
});
describe("GET /users/:id", () => {
test("returns user", async () => {
// Data for testing
const user = await factory.createUser({
name: "demo name",
email: "demo@test.com"
});
// Act
const response = await request(app)
.get(`/users/${user.id}`);
// Assert
expect(response.status).toBe(200);
expect(response.body.name).toBe("demo name");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment