GithubHelp home page GithubHelp logo

Comments (5)

cjroebuck avatar cjroebuck commented on May 18, 2024

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.

tj avatar tj commented on May 18, 2024

a pull-requested test would be more helpful, then I can take a look at fixing it

from supertest.

fengmk2 avatar fengmk2 commented on May 18, 2024

I reappear this bug and also fixed it on #41

from supertest.

ragulka avatar ragulka commented on May 18, 2024

When will this be put to npm? Almost all my tests are failing at the moment

from supertest.

tj avatar tj commented on May 18, 2024

0.5.1

from supertest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.