Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@carlosrpj/jest-mock-express

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@carlosrpj/jest-mock-express

Express mocking library for Jest

  • 1.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Express Mock Jest

This library simulates a http request to load express modules without start the application, working with Jest.

MockRouter

This mock receives the express router exported module. The MockRouter object has all http methods (get, post, put, delete), you can execute requests without start the entire application.

import { MockRouter } from "@carlosrpj/jest-mock-express";
import router from "../../src/routes/api";

const mockRouter = new MockRouter(router);

it("should return a user list", async () => {
  await mockRouter.get("/users");
  expect(mockRouter.res.send).toBeCalledWith([
    { name: "Foo", email: "test@example.com" },
  ]);
});

MockRouter.headers

You can define your request headers with headers function, simulating a http request. This function replace all actual headers.

await mockRouter
  .headers({
    Authorization: "Bearer TOKEN",
    "Content-Type": "application/json",
  })
  .get("/users");

MockRouter.header

Adding a header to request.

await mockRouter.header("Authorization", "Bearer TOKEN").get("/users");

MockRouter.params

Adding many params. This function replace all actual params.

await mockRouter.params({ id: 1 }).get("/users/1");

MockRouter.param

Adding a param to request.

await mockRouter.param("id", 1).get("/users/1");

MockRouter.query

Adding a query to request.
You can use a object with many queries, or a single key/value.

// many queries
await mockRouter.query({ id: 1 }).get("/users/1");
// single key/value
await mockRouter.query("name", "foo").get("/users/1");

MockRouter.body

Adding a body to request.

await mockRouter
  .body({ name: "Foo", email: "test@example.com" })
  .post("/users");

Keywords

FAQs

Package last updated on 20 Apr 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc