Skip to content

Instantly share code, notes, and snippets.

@textbook
Last active April 27, 2022 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save textbook/38d342674a9ec792f06128cc29a16d17 to your computer and use it in GitHub Desktop.
Save textbook/38d342674a9ec792f06128cc29a16d17 to your computer and use it in GitHub Desktop.
const express = require("express");
const request = require("supertest");
const StatusCodes = { CREATED: 201 };
const fakeUserData = {};
const app = express();
it("returns a 201 on successful signup", (done) => {
request(app)
.post("/signup")
.send(fakeUserData)
.expect(StatusCodes.CREATED)
.end((err, res) => {
if (err) {
return done(err);
}
expect(res.body.message).toBe("success");
return done();
});
});
// equivalently:
//
// it("returns a 201 on successful signup", () => {
// return request(app)
// .post("/signup")
// .send(fakeUserData)
// .expect(StatusCodes.CREATED, { message: "success" });
// });
{
"name": "express-supertest",
"version": "0.1.0",
"description": "MRE for https://stackoverflow.com/q/72018137/3001761",
"main": "index.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "Jonathan Sharpe <mail@jonrshar.pe>",
"license": "ISC",
"devDependencies": {
"jest": "^28.0.2",
"supertest": "^6.2.3"
},
"dependencies": {
"express": "^4.18.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment