Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@carlosrpj/jest-mock-express
Advanced tools
This library simulates a http request to load express modules without start the application, working with Jest.
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" },
]);
});
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");
Adding a header to request.
await mockRouter.header("Authorization", "Bearer TOKEN").get("/users");
Adding many params. This function replace all actual params.
await mockRouter.params({ id: 1 }).get("/users/1");
Adding a param to request.
await mockRouter.param("id", 1).get("/users/1");
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");
Adding a body to request.
await mockRouter
.body({ name: "Foo", email: "test@example.com" })
.post("/users");
FAQs
Express mocking library for Jest
The npm package @carlosrpj/jest-mock-express receives a total of 0 weekly downloads. As such, @carlosrpj/jest-mock-express popularity was classified as not popular.
We found that @carlosrpj/jest-mock-express demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.