expressjs - res.status is not a function TypeError
See original GitHub issueHello,
I used supertest with tape, sinon, proxyquire & expressJS, I got this error :
error: res.status is not a function TypeError: res.status is not a function
at <path>\index.ts:26:11
at process._tickDomainCallback (internal/process/next_tick.js:129:7)
(node:21020) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: res.sendStatus is not a function
this is my route function
router.get('/customers', middleware, (req: express.Request, res: express.Response) => {
let options = {
uri: url,
method: 'GET',
};
request(req, options).then(body => {
if (body) {
res.status(200).send(body);
}
}).catch((error) => {
res.sendStatus(500);
});
});
my unit test
import * as test from 'tape';
import * as sinon from 'sinon';
import * as request from 'supertest';
import * as proxyquire from 'proxyquire';
const requestStub = sinon.stub();
const stubResponse = {
statusCode: 200,
body: { body: 'body' }
};
const api = proxyquire('./', { 'api-request': requestStub });
requestStub.returns(Promise.resolve(stubResponse));
test('Get /customers', (assert) => {
const agent = request.agent(api);
agent
.get('/customers')
.expect(200)
.set('Accept', 'application/json')
.end((err, res) => {
var expectedThings =
{
"some" : "data"
};
var actualThings = res.body;
assert.error(err, 'No error');
assert.same(actualThings, expectedThings, 'Retrieve list of things');
assert.end();
});
});
Do you have any idea?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:23
- Comments:24
Top Results From Across the Web
TypeError: res.status is not a function - Stack Overflow
When he named the promise.then response as res , the .then scope assumes the res is from resolved promise, not from express route....
Read more >expressjs - res.status is not a function TypeError · Issue #416
Hello, I used supertest with tape, sinon, proxyquire & expressJS, I got this error : error: res.status is not a function TypeError: ...
Read more >Node.js Connector TypeError: res.status is not a function
I am learning JS scripting and am making a RESTful API with the MariaDB Node.js Connector and Express.js. But I am stuck on...
Read more >res.json, res.status, res.redirect, res.render, res.send is not a ...
In this video, I have explained how we can handle errors such as res.send is not a function in express js. In the...
Read more >TypeError: response.json is not a function in JavaScript
The "response.json is not a function" error occurs when we call the json() method on an object that is not the Response object...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed, in my case… Just add “next” to the variables list (err, req, res, next)
app.use((err, req, res, next) => {
console.error(err);
res.status(500).json({error: 'an error occurred'});
});
From documentation: https://expressjs.com/ru/api.html
I encountered the same error when applying supertest on a express route.