supertest

mocha supertest ECONNRESET

不羁的心 提交于 2019-12-09 13:07:19
问题 I'm testing a Nodejs server with Mocha and Supertest. The test suite has grown to more than 1500 tests. Suddenly, although all of the code under test still works, my test suite fails with this error: { [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' } If I comment out some tests that run earlier, the tests that cause the error change. What is causing this insanity? 回答1: I found the answer in this Google Groups post by Mike Gradek: We used mocha and supertest

Cant test DELETE method using mocha and supertest

十年热恋 提交于 2019-12-06 23:49:38
问题 I'm trying to build a RESTful API for a node app. I built the routes and everything is running fine. But when I try to test it, it cant get the DELETE method to work, despite of it working normally not under tests. Here are the codes for the server and test. Server: // set up var express = require('express'); var app = express(); // create our app w/ express var path = __dirname; //root path // configuration app.configure(function() { app.use(express.static(path)); //app.use(express.logger(

sails.js + mocha + supertest + sinon: how to stub sails.js controller function

僤鯓⒐⒋嵵緔 提交于 2019-12-05 14:17:05
I am trying to stub a sails controller function, but I don't know which object to stub. using sinon.stub(object,'funcname', function()... This is probably related to the way sails bind controller functions... Here is some code to give example Controller file api/controllers/PersonController.js var fs = require('fs'); // // I want to stub retrieveData function when testing // function retreiveData(cb) { fs.readFile('./filedata', function (err, data) { if (err) throw err; cb(data.toString()); }); }; function showdata(req, res) { var stack = new Error().stack console.log( stack ) retreiveData

Cant test DELETE method using mocha and supertest

妖精的绣舞 提交于 2019-12-05 03:18:59
I'm trying to build a RESTful API for a node app. I built the routes and everything is running fine. But when I try to test it, it cant get the DELETE method to work, despite of it working normally not under tests. Here are the codes for the server and test. Server: // set up var express = require('express'); var app = express(); // create our app w/ express var path = __dirname; //root path // configuration app.configure(function() { app.use(express.static(path)); //app.use(express.logger('dev')); // log every request to the console app.use(express.json()); app.use(express.urlencoded()); //

How do I get the actual server error when running supertest in mocha?

对着背影说爱祢 提交于 2019-12-05 01:32:16
I have this code using supertest and mocha: import request from 'supertest'; //.... var newGame; describe('Creating game', function() { beforeEach(function(done) { request(app) .post('/api/games') .send({ owner: 'Mr. X', }) .expect(201) .expect('Content-Type', /json/) .end((err, res) => { if (err) { return done(err); } newGame = res.body; done(); }); }); describe('the created game', function() { it('should name the specified owner', function() { newGame.owner.should.equal('Mr. X'); }); ... }) }); When the server code throws some exception (e.g. accessing properties of an undefined object) I

TypeError: Cannot read property 'address' of undefined supertest

橙三吉。 提交于 2019-12-05 01:05:55
I need some help to resolve my problem with testing on nodejs codes. I'm using mocha and supertest. I'm confused with the implementation in supertest. I don't know to resolved it. I'm trying to automate downloading a file. `describe('GET /entry/:entryId/file/:id/download', function(){ it('should pass download function', function(done){ this.timeout(15000); request(app.webServer) .get('/entry/543CGsdadtrE/file/wDRDasdDASAS/download') .set('Authorization', 'Bearer eyJ0eXAiOiJKV1QiLCJhbGco') .expect(200) .end(function(err, res){ if (err) return done(err); console.log(err, res); done(); }); }); })

res.body is empty in this test that uses supertest and Node.js

不想你离开。 提交于 2019-12-05 01:01:59
I am testing a Node.js API with supertest , and I cannot explain why the res.body object superset returns is empty. The data shows up in the res.text object, but not res.body , any idea how to fix this? I am using Express and body-parser : app.use(bodyParser.json()); app.use(bodyParser.json({ type: jsonMimeType })); app.use(bodyParser.urlencoded({ extended: true })); Here is the API method I am testing: app.get(apiPath + '/menu', function(req, res) { var expiration = getExpiration(); res.set({ 'Content-Type': jsonMimeType, 'Content-Length': jsonTestData.length, 'Last-Modified': new Date(),

Node.js / Express / Mocha / Supertest Rest API - Empty Request Body

你离开我真会死。 提交于 2019-12-05 00:20:15
I've looked everywhere I can to find a solution to this. The only thing I've found is an unanswered post. I apologize if I've overlooked something. The problem is that when I try to get the POST values in the /createQuestion API, the body is empty/undefined. I get errors like this Cannot read proprety 'question' of undefined coming from the API. The Express API: app.post("/createQuestion", function(req, res) { var questionType = req.body.question.type; var questionText = req.body.question.text; var questionDuringClass = req.body.question.duringClass; // Do a bunch of stuff res.send(response);

grunt testing api with supertest, express and mocha

白昼怎懂夜的黑 提交于 2019-12-04 13:04:25
I have an https server running by express, which i test using mocha and supertest. My problem is - if i run only the test - its ok. If i try to run gruntfile with test then run express - i see lot of EADDRINUSE errors, even if in test files i do after() with app.close(). Same applies to watch task on tests. Here is my exapmle test: /* jshint node: true*/ /*global describe, it, after*/ (function() { 'use strict'; process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; var request = require('supertest'); var app = require('../server.js').app; var expect = require('chai').expect; var Cookies; after

How to authenticate Supertest requests with Passport /Facebook strategy/?

☆樱花仙子☆ 提交于 2019-12-04 12:06:21
问题 I'm using Passport.js for authentication (Facebook strategy) and testing with Mocha and Supertest. How can I create a session and make authenticated requests with Supertest for Facebook strategy? Here is the example test for when user not logged in: describe 'when user not logged in', -> describe 'POST /api/posts', -> it 'respond with 401', (done)-> request(app). post(API.url('posts')). set('Accept', 'application/json'). send(post: data). expect('Content-Type', /json/). expect(401, done)