supertest

Two files using supertest with mocha causing EADDRINUSE

血红的双手。 提交于 2019-12-12 08:16:54
问题 I'm using supertest to unit test my server configurations and route handlers. The server configurations tests are in test.server.js and the route handling tests are in test.routes.handlers.js . When I run all the test files using mocha . , I get EADDRINUSE . When I run each file individually, everything works as expected. Both files define and require supertest, request = require('supertest') , and the express server file, app = require('../server.js') . In server.js , the server is started

Sinon - How to stub authentication library (Authy -Twilio)

懵懂的女人 提交于 2019-12-12 03:42:34
问题 I am currently new to Sinon, Mocha, Supertest and in the process to writes tests. In my current scenario, i have authentication library which verifies my "OTP" and after verifying it proceeds to do operation within the callback function. I am unable to mock the callback to return null and carry on to test rest of the code. Following is my code snippet: Controller.js var authy = require('authy')(sails.config.authy.token); authy.verify(req.param('aid'), req.param('oid'), function(err, response)

Unable to send authenticated request in tests using Jest, Supertest, Passport, Koa2

孤街浪徒 提交于 2019-12-11 16:19:31
问题 Despite my best attempts to correctly write test code to authenticate a request agent in Setup blocks or previous describe/it blocks, any request I make from the agent in subsequent describe/it blocks never completes as 200. Example code: const request = require('supertest'); const server = require('../server'); let agent = request.agent(server); let fakePerson = null; beforeEach(async (done) => { fakePerson = await Person.createMock(); agent.post(‘/login’) .send({ email: ‘test@user.com’,

Supertest request with CSRF fails

拟墨画扇 提交于 2019-12-11 15:23:04
问题 I have an Express 4 application that makes user of csurf for CSRF protection on API routes. The application is working perfectly and CSRF protection is indeed working where requests without the csrf-token header will give the appropriate error. I make use of Ava for testing with supertest for testing routes. The following test fails when CSRF checking is enabled but passes if I remove the middleware: test('booking api no auth', async t => { t.plan(4) const server = await request(makeServer(t

Timeout when running mocha test on mongoose model and express route

有些话、适合烂在心里 提交于 2019-12-11 11:49:54
问题 I'm having an issue writing tests for my Mongoose models and my express app (routes) I have a very simple app.js file: var env = process.env.NODE_ENV || 'development', express = require('express'), config = require('./config/config')[env], http = require('http'), mongoose = require('mongoose'); // Bootstrap db connection mongoose.connect(config.db) // Bootstrap models var models_path = __dirname + '/app/model'; fs.readdirSync(models_path).forEach(function(file) { if (~file.indexOf('.js')) {

Streaming data events aren't registered

给你一囗甜甜゛ 提交于 2019-12-11 03:42:38
问题 I'm using superagent to receive a notifications stream from a server require('superagent') .post('www.streaming.example.com') .type('application/json') .send({ foo: 'bar' }) .on('data', function(chunk) { console.log('chunk:' + chunk); // nothing shows up }) .on('readable', function() { console.log('new data in!'); // nothing shows up }) .pipe(process.stdout); // data is on the screen For some reason data and readable events aren't registered, hovewer I can pipe data to the sceeen. How can I

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

谁说胖子不能爱 提交于 2019-12-10 01:36:55
问题 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({

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

我只是一个虾纸丫 提交于 2019-12-10 01:31:54
问题 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'); }); ... })

TypeError: Cannot read property 'address' of undefined supertest

夙愿已清 提交于 2019-12-10 01:24:09
问题 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')

grunt testing api with supertest, express and mocha

十年热恋 提交于 2019-12-09 19:08:04
问题 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'