Skip to content

rook2pawn/supertest-light

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node 7 Build Status Node 8 Build Status
Node 9 Build Status Node 10 Build Status
Node 11 Build Status Node 12 Build Status
Node 13 Build Status
Code Coverage Coverage Status

supertest-light

supertest-light is

  • an ultra-minimalist take on supertest
  • much smaller
  • and removes idiosyncratic aspects such as expect

.get(path)

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!");
  });

.post(path, postData)

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"
    );
  });

About

minimal take on supertest

Resources

Stars

Watchers

Forks

Packages

No packages published