Comments (10)
I happen to have the same problem, and found how to solve it simply.
Do as @mfrobben says, expect(SOME_CODE, done)
when you don't need complete access to the error and the response.
When you need complete access to do custom stuff in the end
callback, test the error as follows :
.end(function(err, res) {
if (err) {
done(err);
} else {
// do your stuff here
}
});
I first tried without an else
statement, but I got this error : Error: done() called multiple times
.
from supertest.
hmm yeah what you expect is correct, I'll take a look
from supertest.
hmm i cant seem to reproduce it, my tests are fine
from supertest.
Thanks for checking. I'll try again tomorrow with a minimum test, and post the results.
from supertest.
I get this same behavior if I don't check for err in end and re-throw.
Example: https://gist.github.com/3722812#file_test.js
Here is a gist with a passing and failing example:
git clone git://gist.github.com/3722812.git gist-3722812
I assume this is the expected behavior, but I might be wrong.
from supertest.
bump. I'm seeing this with a test that I expect to return status 200 yet recieve 500. My call chain is as follows:
superTest(appTest.app)
.post(route)
.set('Content-Type','application/json')
.send(params)
.expect(200)
.end(function(err, res) {
console.log(err) // error is returned here
done()
})
The mocha output (mixed with Console Log) was:
◦ POST /:uid/route with valid params should return 200:
[Error: expected 200 "OK", got 500 "Internal Server Error"]
✓ POST /:uid/route with valid params should return 200
from supertest.
TJ & Silas - FYI, this syntax fixes the issue. Hope this helps tracking down what's going on.
superTest(appTest.app)
.post(route)
.set('Content-Type','application/json')
.send(params)
.expect(200,done)
Output:
✖ 1 of 6 tests failed:
- POST /:uid/route with valid params should return 200:
Error: expected 200 "OK", got 500 "Internal Server Error"
from supertest.
if someone can reproduce it with a pull-request test I'll take a better look, low on time ATM
from supertest.
After reading DjebbZ, this can probably be solved with documentation. Submitting a readme pull request
from supertest.
I was getting this error but it turned out it was because I wasn't separating my redirect/render code paths properly. I forgot to put a return after the redirect so it ended up redirecting then rendering on the same response object.
from supertest.
Related Issues (20)
- Notice regarding the move from @visionmedia org to @ladjs org
- Cookies go to domains they didn't return from
- disabling the debug REQURL CODE line that comes while testing HOT 1
- HTTP2 sample no working
- [fix] TypeError: Cannot read properties of undefined (reading 'address') HOT 1
- cookiejar Regular Expression Denial of Service via Cookie.parse function HOT 3
- `_body` key instead of `body` in response HOT 1
- Its is a good practice for Next.js?
- [fix] timeout doesn't call end with error
- [fix] Module not found: Error: Can't resolve 'http' in '[...]/node_modules/supertest/lib' HOT 1
- [fix] Do no replace invalid body with an empty JSON object HOT 1
- I didnt find supertest latest version updated with latest superagent 8.0.9 HOT 3
- Why I was getting "Jest has detected the following 1 open handle potentially keeping Jest from exiting: Timeout"
- Error: write EPIPE on large files - Next.js + Jest + Supertest HOT 1
- [fix] Cannot send secure cookie over unencrypted connection
- [fix] Next.js: Ubuntu 22.04.3 LTS
- [fix] don't change the requrest url hash HOT 1
- SuperTest is not compatible with Node v18.19.0 Error: ECONNREFUSED: Connection Refused HOT 3
- [fix] write EPIPE error when attaching a file. (small repro)
- supertest version 6.3.3 => 6.3.4 is a breaking change HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from supertest.