Comments (5)
Yep. Just came across this too. I wrote these tests to demonstrate the issue - first one is taken from the readme:
it('should assert status only 1', function(done){
var app = express();
app.get('/user', function(req, res){
res.send(201, { name: 'tobi' });
});
request(app)
.get('/user')
.expect('Content-Type', /json/)
.expect('Content-Length', '20')
.expect(201)
.end(function(err, res){
if (err) throw err;
});
})
it('should assert the status only 2', function(done){
var app = express();
app.set('json spaces', 0);
app.get('/', function(req, res){
res.send({ foo: 'bar' });
});
request(app)
.get('/')
.expect(200)
.end(function(err, res){
err.message.should.equal('expected { foo: \'baz\' } response body, got { foo: \'bar\' }');
request(app)
.get('/')
.expect({ foo: 'bar' })
.end(done);
});
})
1) request(app) .expect(body[, fn]) should assert status only 1:
Error: Error: expected undefined response body, got '{\n "name": "tobi"\n}' (undefined:undefined)
at process.uncaught (/Users/cjroebuck/Dev/supertest/node_modules/mocha/lib/runner.js:492:19)
at process.EventEmitter.emit (events.js:126:20)
2) request(app) .expect(body[, fn]) should assert the status only 2:
Error: AssertionError: expected 'expected undefined response body, got \'{"foo":"bar"}\'' to equal 'expected { foo: \'baz\' } response body, got { foo: \'bar\' }' (undefined:undefined)
at process.uncaught (/Users/cjroebuck/Dev/supertest/node_modules/mocha/lib/runner.js:492:19)
at process.EventEmitter.emit (events.js:126:20)
It must be the change to support multiple body assertions that has caused this bug. The workaround for now is to either don't use expect and do your assertion in the end function callback. So instead of .expect(200)
it would be .end(function(err,res) { res.status.should.equal(200) }
, or if you do use expect.. you need to make sure you specify a body aswell as just a status..
from supertest.
a pull-requested test would be more helpful, then I can take a look at fixing it
from supertest.
I reappear this bug and also fixed it on #41
from supertest.
When will this be put to npm? Almost all my tests are failing at the moment
from supertest.
0.5.1
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.