Last active
April 27, 2022 09:54
-
-
Save textbook/38d342674a9ec792f06128cc29a16d17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }); | |
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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 <[email protected]>", | |
"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