Tag: supertest

获得“错误:string”不是有效的BCrypt哈希“,抛出一个错误:)”在摩卡ExpressJStesting

我有一个使用Passport进行身份validation的MEAN堆栈应用程序。 我试图编写一个unit testing,login并检查您是否被redirect到根( / )。 但是,每当我运行摩卡我得到以下错误信息: 1) POST /home Login test should redirect to / after login: Error: the string "Not a valid BCrypt hash." was thrown, throw an Error 🙂 这是我的unit testingLoginSpec.js : var should = require("should"); var app = require("../app"); var mongoose = require("mongoose"); var User = mongoose.model("User"); var request = require("supertest"); var […]

TypeError:无法读取未定义超类的属性“地址”

我需要一些帮助来解决testingnodejs代码的问题。 我正在使用摩卡和超级特技。 我很困惑与supertest的实施。 我不知道要解决这个问题。 我试图自动下载一个文件。 `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(); }); }); });

如何通过Passport / Facebook战略authenticationSupertest请求/?

我使用Passport.js进行身份validation(Facebook策略),并使用Mocha和Supertest进行testing。 我如何创build一个会话,并与Supertest Facebook的策略进行authentication的请求? 以下是用户未login时的示例testing: 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) 谢谢你的build议:D

如何使用supertest和代理在摩卡testing中进行authentication请求?

我在login后无法运行已validation的testing(服务器返回401 Unauthenticated )。 var should = require('should'), _ = require('lodash'), app = require('../../../server'), mongoose = require('mongoose'), User = mongoose.model('User'), request = require('supertest'); var user , user1; describe('GET /api/jobs', function () { before(function (done) { user = new User({ provider: 'local', name: 'Fake User', email: 'test@test.com', password: 'password' }); // Clear users before testing User.remove().exec(); request(app) […]

使用摩卡和supertest不能testingDELETE方法

我正在尝试为节点应用程序构build一个RESTful API。 我build立了路线,一切运行良好。 但是,当我尝试testing它,它不能让DELETE方法工作,尽pipe它通常不在testing中正常工作。 这里是服务器和testing的代码。 服务器: // 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()); // pull information from html in POST app.use(express.methodOverride()); // simulate DELETE […]

NodeJS超级访问会话对象

我用supertesttesting我的Node.js应用程序。 在我的控制器中,我访问会话对象。 为了提出有效的请求,这个会话对象需要填充一些数据。 调节器 // determine whether it is user's own profile or not var ownProfile = userId == req.session.user._id ? true : false; testing it('profile', function (done) { testUserOne.save(function(error, user){ request .agent(server) .get('/profile?userId=' + user._id) .expect('Content-Type', /html/) .expect(200) .expect(/Profile/) .end(done); }) }); 题 我怎样才能嘲笑的REQ /会议对象?

在这个使用supertest和Node.js的testing中,res.body是空的

我正在用supertesttesting一个Node.js API,我无法解释为什么res.body对象超集返回是空的。 数据显示在res.text对象中,但不res.body ,任何想法如何解决这个问题? 我正在使用Express和body-parser : app.use(bodyParser.json()); app.use(bodyParser.json({ type: jsonMimeType })); app.use(bodyParser.urlencoded({ extended: true })); 这是我正在testing的API方法: app.get(apiPath + '/menu', function(req, res) { var expiration = getExpiration(); res.set({ 'Content-Type': jsonMimeType, 'Content-Length': jsonTestData.length, 'Last-Modified': new Date(), 'Expires': expiration, 'ETag': null }); res.json({ items: jsonTestData }); } 以下是我对这个API方法执行的testing: describe('GET /menu', function() { describe('HTTP headers', function() { it('responds with […]

在远程URL上重复使用Supertesttesting

我正在使用MochaJS和SuperTest在开发过程中testing我的API,绝对喜欢它。 不过,我也想把这些相同的testing变成远程testing我的登台服务器,然后把代码推到生产。 有没有办法通过远程URL或代理向远程URL提供请求? 这是我使用的一个testing样本 request(app) .get('/api/photo/' + photo._id) .set(apiKeyName, apiKey) .end(function(err, res) { if (err) throw err; if (res.body._id !== photo._id) throw Error('No _id found'); done(); });

如何使用Jasmine 2.3和SuperTesttestingExpress.js路由

我使用通过NPM安装的Jasmine 2.3 ,并使用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'); }; 我导出了一个Express.js应用程序对象,并将其与SuperTest一起用于我的规范中。 'use strict'; var supertest = require('supertest') var application = require('../../../../../server'); describe('GET /api/users', function() { it('should respond with json', function(done) { supertest(application) .get('/api/users') .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect(200, done); }); }); 当我运行规范时,即使预计有200状态码, […]

在摩卡上运行supertest时,如何得到实际的服务器错误?

我有使用supertest和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'); }); […]