Node 7 | Node 8 | ||
---|---|---|---|
Node 9 | Node 10 | ||
Node 11 | Node 12 | ||
Node 13 |
Code Coverage |
---|
supertest-light is
- an ultra-minimalist take on supertest
- much smaller
- and removes idiosyncratic aspects such as
expect
const request = require("supertest-light");
const assert = require("assert");
const app = require("express")();
app.get("/user/:username/messages", (req, res, next) => {
assert.equal(req.headers["user-agent"], "Supertest-Light");
return res.end(`Hello ${req.params.username}!`);
});
request(app)
.set("User-Agent", "Supertest-Light")
.get("/user/bart/messages")
.then(res => {
assert.equal(res.text, "Hello bart!");
});
const request = require("supertest-light");
const express = require("express");
const assert = require("assert");
const app = express();
app.post("/user/:userId/messages", express.json(), (req, res, next) => {
return res.end(`doubled: ${req.body.num * 2}`);
});
request(app)
.post("/user/a1234/messages?language=en", { num: 34 })
.then(res => {
assert.equal(
res.text,
"doubled: 68",
"postData received and text is property assigned to response"
);
});