node.js - Object is not a Function - SuperTest -


i'm not sure why it's throwing error , it's saying not function.

    'use strict';    var koa = require("koa");     var app = koa();     var chai = require('chai');     var expect = chai.expect;      var request = require('supertest');      describe('feature: car rest endpoint', function () {          context('scenario: car', function () {              var url = 'http://localhost/search/cars';              describe('given: resource accessed @ resource url' + url, function () {                  describe('then: receive successful response', function(){                      it('status code should 200', function (done){                         request(app)                             .get(url)                             .expect(200,done);                     });                 }); 

it says it's line .expect(200,done) might wrong.

i tried no luck:

 request(app)                     .get(url)                     .expect(200)                     .end(function(err, res){                         if (err) return done(err);                         done()                     }); 

i tried var request = require('supertest').agent(koa);

enter image description here

your problem you're passing http://localhost #get(url). change url /search/cars. i've got full repro (using express)

var request = require('supertest'), express = require('express');  var app = express();  app.get('/user', function(req, res) {   res.send(200, {     name: 'tobi'   }); });  request(app)   .get('http://localhost/user')   .expect(200)   .end(function(err) {     if (err) throw err;     console.log('success!');   }); 

output:

    if (res.status !== status) {            ^ typeerror: cannot read property 'status' of undefined     @ test.assert (c:\workspace\choose-your-own\node_modules\supertest\lib\test.js:202:12)     @ server.assert (c:\workspace\choose-your-own\node_modules\supertest\lib\test.js:131:12)     @ server.g (events.js:199:16)     @ server.emit (events.js:104:17)     @ net.js:1392:10     @ process._tickcallback (node.js:355:11) 

when use /user, get:

success! 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -