1

I'm going off of this tutorial, trying to make tests with Mocha, Supertest, and Should.js.

I have the following basic test to create a user through a PUT endpoint that accepts it's data in headers.

describe('User Routes', function () {
    it('should allow me to make my user', function (done) {
        request(url)
        .put('/users')
        .set(myCreds)
        // end handles the response
        .end(function(err, res) {
              if (err) {
                throw err;
              }
              // this is should.js syntax, very clear
              res.should.have.status(201);
              done();
            });
        });

However, while the endpoint does trigger, and the user does get made, the code throws an error that should is undefined... Uncaught TypeError: undefined is not a function.

I have

var should = require('should');
var assert = require('assert');
var request = require('supertest');

At the top of the file, so why would it be undefined?

Jackson
  • 559
  • 7
  • 20
  • 1.) Just to rule that out, are you sure you have installed the `require`d packages? (`npm install --save-dev should assert supertest`) 2.) What is the value of `res` when the exception is thrown? – Leon Adler Nov 16 '15 at 00:11

1 Answers1

2

You are calling should incorrectly, try this:

res.should.have.property('status', 201)

or

res.status.should.be.equal(201)

or

should.equal(res.status, 201)

or install should-http.

jgillich
  • 71,459
  • 6
  • 57
  • 85