Gathering detailed insights and metrics for supertest-as-promised
Gathering detailed insights and metrics for supertest-as-promised
Gathering detailed insights and metrics for supertest-as-promised
Gathering detailed insights and metrics for supertest-as-promised
@types/supertest-as-promised
TypeScript definitions for supertest-as-promised
supertest-session-as-promised
Cookie-based session persistence for Supertest-as-promised
@ryancavanaugh/supertest-as-promised
Type definitions for SuperTest as Promised v2.0.2 from https://www.github.com/DefinitelyTyped/DefinitelyTyped
retyped-supertest-as-promised-tsd-ambient
TypeScript typings for supertest-as-promised
Supercharge supertest with a promise interface
npm install supertest-as-promised
Typescript
Module System
Node Version
NPM Version
90.8
Supply Chain
99.5
Quality
74.4
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
9,307,481
Last Day
1,463
Last Week
20,846
Last Month
88,121
Last Year
1,242,217
MIT License
269 Stars
61 Commits
24 Forks
29 Watchers
2 Branches
7 Contributors
Updated on Oct 29, 2024
Minified
Minified + Gzipped
Latest Version
4.0.2
Package Id
supertest-as-promised@4.0.2
Size
6.88 kB
NPM Version
2.15.1
Node Version
0.10.48
Published on
Nov 02, 2016
Cumulative downloads
Total Downloads
1
SuperTest as Promised supercharges SuperTest with a then
method.
Instead of layering callbacks on callbacks in your tests:
1request(app) 2 .get("/user") 3 .expect(200, function (err, res) { 4 if (err) return done(err); 5 6 var userId = res.body.id; 7 request(app) 8 .post("/kittens") 9 .send({ userId: userId, ... }) 10 .expect(201, function (err, res) { 11 if (err) return done(err); 12 13 // ... 14 }); 15 });
chain your requests like you were promised:
1return request(app) 2 .get("/user") 3 .expect(200) 4 .then(function (res) { 5 return request(app) 6 .post("/kittens") 7 .send({ userId: res}) 8 .expect(201); 9 }) 10 .then(function (res) { 11 // ... 12 });
SuperTest as Promised operates just like normal SuperTest, except that the
object returned by .get
, .post
, etc. is a proper
thenable:
1var express = require("express") 2 , request = require("supertest-as-promised"); 3 4var app = express(); 5 6request(app) 7 .get("/kittens") 8 .expect(200) 9 .then(function (res) { 10 // ... 11 });
If you use a promise-friendly test runner, you can just
return your request
chain from the test case rather than messing with a
callback:
1describe("GET /kittens", function () { 2 it("should work", function () { 3 return request(app).get("/kittens").expect(200); 4 }); 5});
If you use a SuperTest agent to persist cookies, those are thenable too:
1var agent = require("supertest-as-promised").agent(app); 2 3agent 4 .get("/ugly-kitteh") 5 .expect(404) 6 .then(function () { 7 // ... 8 })
To start, only the then
and catch
methods are exposed. But once you've
called .then
or .catch
once, you've got a proper Bluebird promise that
supports the whole gamut of promisey goodness:
1request(app) 2 .get("/kittens") 3 .expect(201) 4 .then(function (res) { /* ... */ }) 5 // I'm a real promise now! 6 .catch(function (err) { /* ... */ })
See the Bluebird API for everything that's available.
You may find it cleaner to cast directly to a promise using the toPromise
method:
1request(app) 2 .get("/kittens") 3 .expect(201) 4 .toPromise() 5 // I'm a real promise now! 6 .delay(10) 7 .then(function (res) { /* ... */ })
Promise
You can supply own promise library so that the promises returned have your convenience methods of choice.
Simply call the SuperTest as Promised module with a ES6-compliant Promise
constructor, and you'll get back a new module configured to return your custom
promises. To swap in when.js, for example:
1var when = require("when") 2 , request; 3 4request = require("supertest-as-promised")(when.Promise); 5request(app) 6 .get("/when.js") 7 .then(function (res) { /* ... */ }) 8 // I'm a when.js promise! (instanceof when.Promise == true) 9 .frobulate() 10 11request = require("supertest-as-promised"); 12request(app) 13 .get("/bluebird.js") 14 .then(function (res) { /* .. */ }) 15 // I'm back to the default Bluebird promise!
Suppose your snazzy test
1it("should get kittens", function () { 2 return request(app).get("/kittens").expect(200) 3 .then(function (res) { 4 return expect(res.body).to.equal("kittens r cute!"); 5 }); 6});
suddenly starts failing with a "400 Bad Request" error. It'd sure be
handy if you could print out the response body to see if the server
mentioned what, in particular, was bad about your test. Chain on a
.catch
and inspect err.response
:
1it("should get kittens", function () { 2 return request(app).get("/kittens").expect(200) 3 .then(function (res) { 4 return expect(res.text).to.equal("kittens r cute!"); 5 }) 6 .catch(function (err) { 7 console.log(err.response.text); // "You have viewed too many kittens today." 8 }); 9});
1$ npm install supertest supertest-as-promised
SuperTest as Promised lists supertest
as a
peer dependency, so it'll wrap whatever version of SuperTest
you've asked for in your own package.json
.
In earlier versions of NPM, failing to list SuperTest as a dependency would get you the latest version. In NPM 3, failing to list SuperTest as a dependency will generate a warning and SuperTest will not be installed.
Do note that SuperTest as Promised is a well-behaved citizen and doesn't monkey-patch SuperTest directly:
1// I return thenables! 2var request = require("supertest-as-promised"); 3 4// I'm lame and force you to use callbacks 5var request = require("supertest");
We follow semver: the major version number will be upgraded with any breaking change. Breaking changes in each major version are listed below. Consult the changelog for a list of meaningful new features in each version; consult the commit log for a complete list.
.catch
handlers, err.response
is now marked as non-enumerable.No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
Found 2/28 approved changesets -- score normalized to 0
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-09
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreLast Day
12.2%
1,463
Compared to previous day
Last Week
-10.4%
20,846
Compared to previous week
Last Month
-14.8%
88,121
Compared to previous month
Last Year
3.1%
1,242,217
Compared to previous year