node-mocks-http is a package in NPM which mocks 'http' objects for testing express routing functions in web applications that have code which requires mockups of the request and response objects from http.
Questions tagged [node-mocks-http]
8 questions
4
votes
1 answer
Trying to mock response body from a fetch for a unit test
I'm pretty new to sinon and proxyquire and I think I've read all the answers here on SO but I'm still not finding out what I need. Anyway, here's a sanitized version of my code.
const fetch = require('node-fetch');
async function deleteID(id,…

Paul Cezanne
- 8,629
- 7
- 59
- 90
2
votes
0 answers
How can I use node-mocks-http when mocking the AWS SDK?
I've got an existing working test that is testing a route in an Express app (trimmed code):
const AWS = require('aws-sdk-mock');
const AWS_SDK = require('aws-sdk');
AWS.setSDKInstance(AWS_SDK);
...
before(() => {
sendEmailMock =…

jcollum
- 43,623
- 55
- 191
- 321
0
votes
0 answers
Node-mocks-https throwing build issue after node 18 upgrade
I have a requirement to migrate to node 18 from 16 for node application.
am getting below error while npm run test
/apps/node_modules/node-mocks-http/lib/mockRequest.js: Unexpected token * (550:54)
mockRequest[Symbol.asyncIterator] = async function*…

Lokesh
- 59
- 1
- 11
0
votes
0 answers
node.js/typescript test: Unit test should return json body (proper typescript)
I have a test "should return json body"
orderController.test.ts
import { Request, Response } from "express";
import { createOrder } from "../../controllers/orderController";
import { Orders } from "../../models/orders";
import httpMocks from…

track_p54skate
- 81
- 1
- 6
0
votes
1 answer
node.js/typescript test: Unit test should return 201 response code
I have a test 'should return 201 response code' which is failing:
Expected: 201
Received: 200
orderController.ts
import { Request, Response } from "express";
import { Orders } from "../models/orders";
const createOrder = async ( req: Request, res:…

track_p54skate
- 81
- 1
- 6
0
votes
1 answer
Next.js problems with auto bodyParser feature when using jest + node-mocks-http for testing
I am using Next.js to build a simple api and I make use of the automatic bodyParser Feature which parses the body based on the content-type (https://nextjs.org/docs/api-routes/api-middlewares). When fetching the api from the Frontend everything…

Placeprom
- 64
- 7
0
votes
3 answers
Jest testing async function - Jest did not exit one second after the test run has completed
I want to test my Next.js API functions with Jest using node-mocks-http.
This is the function I want to test:
export default async (
req: NextApiRequest,
res: NextApiResponse
): Promise => {
const foods = await getFoods()
…

Tom
- 1,358
- 2
- 14
- 36
0
votes
2 answers
node-mocks-http is not emitting 'end' event
OK, so I have all of these tests that depend on node-mocks-http in mocha to test my express.js controllers and they are all still working just fine.
The problem is that any new tests I create refuse to emit the 'end' event and finish. It got tot…

San Francisco Sunrise
- 143
- 2
- 7