Ragnar
Ragnar

Reputation: 2690

Chai/Moka -> TypeError: request.get(...).expect is not a function

First time with TDD. I'm using the duo Chai/Moka after reading some article online for my NodeJS API.

I already made few dumb test to learn how to use those. Now I want test my API so I created a route :

app.get('/hello', function(req, res) {
  res.status(200).send('Hello World!')
})

I try a test like this :

var request = require('superagent')
var expect = require('Chai').expect

[...]

describe('When request baseURL/hello', function(){
    it('should salute you !', function (done) {
      request
      .get(baseURL + '/hello')
      .expect(200)
      .end(function(err, res){
        if(err) return done(err)
        done()
      })
    })
  })

I have the fail output :

TypeError: request.get(...).expect is not a function

If I comment the expect line everything is working. I try this route with Postman and I have a 200 status code like expected.

Upvotes: 1

Views: 2417

Answers (1)

Traveling Tech Guy
Traveling Tech Guy

Reputation: 27811

I think you're using the wrong test module: you need supertest, not superagent. Just install the supertest module, change the require line, and try again.

Upvotes: 2

Related Questions