
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
express-request-mock
Advanced tools
A convenient wrapper for node-mocks-http which makes testing Express controllers and middleware easy.
A convenient wrapper for node-mocks-http which makes testing Express controllers and middleware easy.
import requestMock from 'express-request-mock'
import handler from '../routes/animals'
it('returns a 200 response', async () => {
const { response } = await requestMock(handler, options)
expect(response.statusCode).toEqual(200)
})
This is a Node.js module available through the npm registry. Node.js 18 or higher is required.
$ npm install --save-dev express-request-mock
This package provides one function which accepts three arguments:
createRequest
(the options are documented here.)The function returns a promise which will resolve when the response is ended or the fallthrough function (next()
) is called. The promise will reject if the underlying code throws an error or the fallthrough function is called with an error.
When resolved the promise will to an object with the following keys:
request
: The request object created by createRequest
response
: The response object created by createResponse
Below is a complete example demonstrating the use of express-request-mock
to test an Express route handler:
import { describe, it } from 'node:test'
import assert from 'node:assert'
import requestMock from 'express-request-mock'
import handler from '../routes/animals'
describe('Controllers - Animals', () => {
describe('when a valid species is requested', () => {
const options = { query: { species: 'dog' } }
it('returns a 200 response', async () => {
const { response } = await requestMock(handler, options)
assert.equal(response.statusCode, 200)
})
})
describe('when a non-existent species is requested', () => {
const options = { query: { species: 'unicorn' } }
it('returns a 404 response', async () => {
const { response } = await requestMock(handler, options)
assert.equal(response.statusCode, 404)
})
})
describe('when an invalid request is received', () => {
const options = { query: {} }
it('calls the fallthrough function with an error', async () => {
const call = () => requestMock(handler, options)
await assert.rejects(call, {
name: 'NoSpeciesProvided',
message: 'You must provide a species',
})
})
})
})
express-request-mock is MIT licensed.
v4.0.0
node-mocks-http
package to v1.13.0FAQs
A convenient wrapper for node-mocks-http which makes testing Express controllers and middleware easy.
The npm package express-request-mock receives a total of 1,701 weekly downloads. As such, express-request-mock popularity was classified as popular.
We found that express-request-mock 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.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.