question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type Error: res.status is not a function supertest

See original GitHub issue

`TypeError: res.status is not a function

  49 |     })
  50 |     .catch(error => {
> 51 |       return res.status(400).json({
     |                  ^
  52 |         success: false,
  53 |         error,
  54 |         results: null

  at status (Routes/Controllers/auth/index.js:51:18)`

router.post('/signup', (req, res) => { let validate = ajv.compile(signupSchema); let valid = validate(req.body); if (!valid) { return res.status(400).json({ success: false, error: sumErrors(validate.errors), results: null }); } auth .signup(req.body) .then(results => { console.log(res.json); return res.status(200).json({ success: true, error: null, results }); }) .catch(error => { return res.status(400).json({ success: false, error, results: null }); }); });

Link to the project online-judge

When testing, with supertest this problem seems to exist.

But the same code works perfectly fine when I start the server manually using npm start and when requests are sent using postman.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

7reactions
Askerov-Acommented, Mar 22, 2020

It happens when you try to test the express.Router() instance. Using express() instead of express.Router() solved my problem.

4reactions
beckaberhanucommented, Jul 14, 2021

Can you explain why express() works differently from express.Router() when using supertest?

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
TypeError: res.status is not a function - Stack Overflow
You are getting this error: TypeError: res.status is not a function. Because the order should be (err, res, req, next) not (req, res,...
Read more >
Node.js Connector TypeError: res.status is not a function
js Connector TypeError: res. status is not a function. I am learning JS scripting and am making a RESTful API with the MariaDB...
Read more >
Supertest - npm
SuperAgent driven library for testing HTTP servers. Latest version: 6.3.3, last published: 21 days ago. Start using supertest in your ...
Read more >
supertest.Response.status JavaScript and Node.js code ...
end(function(err,res){ res.status.should.equal(200); ... We only delete Queue from array, deleted Queues still effect the length... should.not.exist(broker.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found