You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

mini-application

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mini-application

Express app and sinon mocks to the rescue!

1.0.0
npm
Version published
Weekly downloads
3
-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

Mini Application

Express app and sinon mocks to the rescue!

Installation

npm i mini-application --save

yarn add -S mini-application

const MiniApplication = require("mini-application")
const miniApp = new MiniApplication();

Stub

What happens when you wrap Express middleware with Sinon stub? See below:

Stub simple endpoint

const MiniApplication = require("mini-application")
const miniApp = new MiniApplication();

miniApp.stubApp("/test").respond((req, res) => {
  res.end("ok!");
});

miniApp.listen(3000)
.then(() => {
  rp.get("http://localhost:3000/test")
    .then((response) => {
      assert(response.body === "ok!");
    });
});

Stub different responses

miniApp.stubApp("/test")
  .onFirstCall()
  .respond((req, res) => res.end("first response"))
  .onSecondCall()
  .respond((req, res) => res.end("first response"));

Stub specific method only

miniApp.stubApp("post", "/test").respond((req, res) => res.end("on post call only"));

Use sinon helpers

miniApp.stubApp("/test").respond({ text: "json response" });
// or
miniApp.stubApp("/test").respond(503);
// or
miniApp.stubApp("/test").respond("ok");

Events

It's often helpful to get nice callback the verify the expectations

Simple event emitted for path

request.get("http://localhost:3000/test").end();
miniApp.on("incoming.request@/test", (req) => {
  expect(req.url).to.be.equal("/test");
  done();
});

FAQs

Package last updated on 10 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts