Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

res.should.have.status gives me error

I'm new to mocha and should.js. I'm trying to check the response's status but it gives me TypeError: Object #<Assertion> has no method 'status' The code is like this:

describe('Local signup', function() {
    it('should return error trying to save duplicate username', function(done) {
      var profile = {
        email: '[email protected]',
        password: 'Testing1234',
        confirmPassword: 'Testing1234',
        firstName: 'Abc',
        lastName: 'Defg'
      };
      request(url)
          .post('/user/signup')
          .send(profile)
          .end(function(err, res) {
            if (err) {
              throw err;
            }
            res.should.have.status(400);
            done();
          });
    });

I also noticed that although I have declared var should = require('should'); , my ide notifies me that 'should' is a unused local variable. I don't really know why.

like image 402
Charlie Avatar asked Jan 06 '15 01:01

Charlie


2 Answers

Try

res.status.should.be.equal(400);

or

 res.should.have.property('status', 400);

And about " 'should' is a unused local variable". It's true. You don't use should directly. Only sideeffects. Try require('should'); instead.

like image 76
Yury Tarabanko Avatar answered Sep 23 '22 18:09

Yury Tarabanko


Place the line:

require('should-http');

somewhere in your code. E.g.:

require('should-http');

describe('Test Something', function() {
    ...
like image 22
Jason Avatar answered Sep 25 '22 18:09

Jason