FAQ Database Discussion Community


How to get my node.js mocha test running?

javascript,node.js,mocha,supertest
I have developed a service in node.js and looking to create my first ever mocha test for this in a seperate file test.js, so I can run the test like this: mocha test I could not figure out how to get the reference to my app, routes.js: var _ =...

Why is address undefined in my app?

node.js,express,jasmine,supertest
I have a simple express app: var express = require('express'); var path = require('path'); var app = express(); exports.app = app; var index = require('./routes/index'); app.use(express.static(path.join(__dirname,'client/dist/'))); app.get('/', index.get); function start(){ var port = process.env.PORT || 8080; app.listen(port, function(){ console.log('app is running on port: ' + port); }); }; exports.start =...

Created rest ressource in Hapijs

node.js,testing,mocha,hapijs,supertest
I'm building a node REST API server built with hapi.js, for a CRUD ressource, and for the Ressource creation, I want to set the location header and status code using created rather than code(201).header('location.... According the current API Documentation, created(uri) - sets the HTTP status code to Created (201) and...

Create proxy according URL path

javascript,node.js,proxy,supertest,node-http-proxy
I need to create proxy according to some URL which is coming from the browser, since I fairly new to this topic Im not sure how to test it...:( I need some way to test it and see that this is actually working I use this following code from this...

Possible to remove User-agent header in supertest test?

supertest
I am trying to write some Supertest test cases where the User-Agent header is sent with a value, blank, or not at all. I know I can use .set to handle setting a value for that header or '' for blank, but I am not sure how to omit the...

How to run supertest in authenticated endpoints generated by the angular fullstack generator

node.js,express,passport.js,supertest,angular-fullstack
I am trying to use supertest to test the behaivour of an authenticated enpoint that I made using the yeoman angular full stack generator. I tryed using the simple auth as described in the the supertests docs but I am still getting 404 errors. The endpoint and the test are...

How to test Express.js routes with Jasmine 2.3 and SuperTest

node.js,jasmine,supertest
I'm using Jasmine 2.3 installed via NPM and executed with Grunt. 'use strict'; module.exports = function(grunt) { grunt.initConfig({ package: grunt.file.readJSON('package.json'), exec: { jasmine: 'node_modules/.bin/jasmine' } }); require('load-grunt-tasks')(grunt); require('time-grunt')(grunt); grunt.registerTask('default', 'exec:jasmine'); }; I exported an Express.js application object and using it in my specs along with SuperTest. 'use strict'; var supertest...

Why is supertest returning an error when everything passes?

javascript,mocha,supertest
My test looks like: it('should create a user with an email address and password', function(done) { return request.post('/v1/users').send(defaultUser).expect(200).expect(function(res) { console.log(res.body); res.body.should.have.property('id'); res.body.should.have.property('name'); res.body.should.have.property('email'); res.body.should.have.property('username'); return res.body.should.have.property('entities')["with"].lengthOf(1); }).end(done); }); res.body looks like { id: 17, name: 'Satoshi Nakamoto', email:...

NodeJS and supertest : start tests with npm command

node.js,testing,command,npm,supertest
I use supertest : enter link description here I want to launch all tests in tests directory : My /tests/tests.js file : var request = require('supertest'); var app = require('express.io')(); //add good url with http:// and redirection request(app) .post('/add/') .expect(201) .send({url: 'http://www.google.fr'}) .end(function(err, res){ console.log(res.body.url); if (err) throw err; request(app)...

How to use Mocha and Supertest to send malformed JSON?

json,node.js,mocha,supertest
I have the current test I want to run: var request = require('supertest'); it('should be malformed json', function(done) { request(config.base) .post('/authenticate') .send('{"project":{"description":\'test"}}') .set('Authorization', 'Bearer ' + config.token) .expect('Content-Type', /json/) .expect(status.BAD_REQUEST); }); However, supertest seems to validate it, and it just sends '{}' in the body. Any idea how I can...

How to test multiple calls without empty callback

javascript,node.js,express,supertest
I have a scenario where I want to make multiple REST calls to a Node.js service served by Express within a single test, namely: var request = require('supertest'), should = require('should'), game = require('../game.js').app; describe('single pin game of bowling', function(done) { it('should return 20', function(done) { for(var i = 0;...

Getting “TypeError: object is not a function” when using supertest/superagent in forEach loop

javascript,node.js,supertest,superagent
I'm using supertest to test a set of URLs by the same rules. var urls = [ "https://www.example.com", "https://www.example2.com" ]; urls.forEach(function (url) { console.log('begin'); request = request(url) .get('') .expect(200) .end(function (err, res) { // Check for something }); console.log('end'); }); When there is only 1 URL in the array, it...

Supertest and Mongoose Middleware (post remove)

express,mongoose,mocha,chai,supertest
I have been fiddling with this for days, and I cannot figure out why the Mongoose middleware is not being invoked. So I have an API in node.js and I have a website using Angular.js. The Mongoose middleware is this: schema.post('remove', function (doc) { console.log('doctors - post - remove'); });...

Supertest + Express won't fail

node.js,express,supertest
This is more or less a duplicate of supertest test express middleware but after a year, I figured I'd start a new question. var express = require('express'); var request = require('supertest'); var app1 = express(); app1.get('/myapp', function (req, res) { res.send(200, { name: 'myapp' }); }); request = request(app1); it('should...

How can I test if my Express app's response contains certain HTML tags / text?

node.js,express,mocha,supertest
I'm running an Express Node server, and using Mocha and Supertest to test my routes. I would like to be able to test for the existence of certain text in the response for one of my Express routes, as so: it('should display form text input', function(done) { request(app) .get('/') .end(function...