Tag: mocha

摩卡testing中无法将socket.io-client连接到服务器

试图连接socket.io客户端到节点服务器我得到以下错误使用DEBUG = * mocha:runner run suite Chat Server Message Events +1ms Message Events socket.io-client:url parse http://localhost:5000 +1s socket.io-client ignoring socket cache for http://localhost:5000 +0ms socket.io-client:manager readyState closed +1ms socket.io-client:manager opening http://localhost:5000 +2ms engine.io-client:socket creating transport "websocket" +1ms engine.io-client:socket setting transport websocket +7ms socket.io-client:manager connect attempt will timeout after 20000 +1ms socket.io-client:manager readyState opening +1ms engine.io-client:socket […]

使用MochatestingReact组件:意外令牌

我有我的React组件都充实,我想学习如何用Mocha + chai正确地testing这些组件。 我有这些configuration为我的package.json (相关的): "scripts": { "start": "http-server", "build": "watchify main.js -t babelify -o bundle.js", "test": "./node_modules/mocha/bin/mocha –compilers js:babel-core/register test/test*.js" }, "devDependencies": { "babel": "^5.6.23", "babelify": "^6.1.3", "browserify": "^11.0.0", "chai": "^3.5.0", "jsdom": "^9.8.3", "mocha": "^3.2.0", "react-addons-test-utils": "^15.4.1" }, "babel": { "presets": [ "es2015" ] } 我有Skill.js : import React from 'react'; import _ from […]

TypeError:“string”必须是string,Buffer或ArrayBuffer

使用Multiparty NPM模块为multipart / form-data开发了一个Node代理应用程序。 我想用Mocha和Chai来testing应用程序。 在运行testing用例时,我得到“TypeError:”string“必须是string,缓冲区或ArrayBuffer”错误。 我的代码片段是: it('<test case description comes here>', (done) => { chai.request(app) .post('<my post url comes here>') .set('Content-Type', 'multipart/form-data; boundary=' + Math.random()) .send({emailField: 'test@xyz.com', xyzField: 'Some Data'}) .attach('file', 'test.txt') .end((error, result) => { if (error) { console.log(error); } result.should.have.status(200); result.should.not.be.empty; done(); }); }); 任何帮助,将不胜感激。

未处理的Promise拒绝警告:TypeError:第一个参数必须是string或缓冲区

问题似乎是重复的,但我一直在努力解决这个从最近3个小时。 基本上我使用supertest & mocha来testing我的API。 我无法理解哪个承诺没有得到解决。 app.post('/todos', (req, res) => { var todo = new Todo({ text : req.body.text }); todo.save().then( (doc) => { res.status(200).send(doc) }, (e) => { res.status(400).end(e); }); }); 以下是我写的testing: const expect = require('expect'); const request = require('supertest'); var {app} = require('./../server'); var {Todo} = require('./../models/todo'); // Setup database beforeEach((done) => { Todo.remove({}) […]

用无服务器正确实现babel

在我们的项目中,我们最近决定,对于某些实现,es6 +函数使我们的生活变得更加简单。 然而,这个“更容易”并没有被babel与无服务器结合的翻译。 项目结构如下: + |- serverless.yaml |- package.json |- .babelrc |- /src |- handler.js |- package.json |- /test |- test.js 这显示了整个项目文件夹。 以下是各个文件的源代码。 serverless.yaml provider: name: aws runtime: nodejs6.10 functions: getHello: handler: handler.lambdaGetHello events: – http: path: api/hello method: GET authorizer: aws_iam cors: true package: include: – handler.js – node_modules/** package.json(顶层,请注意,这可能有太多的包,实际的代码有更多的用法,但清理这可能是为了) { "name": "Default-package-JSON-file", "version": […]

用Mongoosetestingasynchronous中间件function

我正在Mongoose中使用一个save中间件来在数据库中创build一个活动日志,只要采取一些行动。 就像是 UserSchema.post("save", function (doc) { mongoose.model("Activity").create({activity: "User created: " + doc._id}); }); 这似乎工作正常,但问题是,我不能testing它,因为没有办法传递一个callback post (这可能没有意义)。 我用mochatesting了这一点: User.create({name: "foo"}, function (err, user) { Activity.find().exec(function (err, act) { act[0].activity.should.match(new RegExp(user._id)); done(); }); }); 问题是,调用.find之前, Activity.create显然没有完成。 我可以通过在setTimeout包装.find来解决这个问题,但是这对我来说似乎很.find 。 有什么方法可以testingasynchronousmongoose中间件操作?

摩卡如何确定嵌套级别?

目前我正试图了解如何BDD DSL在摩卡工作,我卡住了。 我想要这个方法,并想要应用这个。 例如,下面的testing: describe('foo', function(){ describe('bar', function(){ it('should be something') }); }); 会产生输出: foo bar – should be something 0 passing (4ms) 1 pending 问题:嵌套块中的全局函数describe如何describe确定为嵌套? 我查看了源代码,但现在无法处理主要的想法。

loopback.io错误:发送后无法设置标头。 确认用户

我正在使用摩卡和supertest来创buildfunctiontesting。 以下是testing的副本。 it("should verify user POST /api/User/confirm", function (done) { app.models.Users.findById(userId, function (err, usr) { json('get', '/api/user/confirm?uid=' + userId + '&token=' + usr.verificationToken) .expect(204,done); }); }); 然而这个testing返回: Error: Can't set headers after they are sent. at ServerResponse.OutgoingMessage.setHeader (http.js:689:11) at ServerResponse.res.setHeader (/node_modules/loopback-explorer/node_modules/express/node_modules/connect/lib/patch.js:134:22) at ServerResponse.header (/node_modules/loopback/node_modules/express/lib/response.js:700:10) at ServerResponse.send (/node_modules/loopback/node_modules/express/lib/response.js:154:12) at ServerResponse.json (/node_modules/loopback/node_modules/express/lib/response.js:240:15) at ServerResponse.send (/node_modules/loopback/node_modules/express/lib/response.js:142:21) at defaultHandler […]

咕噜摩卡没有发现目标的错误

我正在尝试使用grunt,mocha和chai编写节点api的testing。 我不知道如何require其他库。 我是一个初学者,咕噜,摩卡,柴,和一般的testing… 我的Gruntfile: // Gruntfile.js module.exports = function(grunt){ grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), // Mocha Test mochaTest: { test: { options: { reporter: 'list', timeout: 15000 }, src: ['test/groupstest.js'] } } }); // Load grunt mocha task grunt.loadNpmTasks('grunt-mocha'); grunt.loadNpmTasks('grunt-mocha-test'); }; 文件结构: ├── package.json ├── Gruntfile.js ├── test │ └── groupstest.js └── … groupsheets: 'use strict'; var […]

用Chai,Mocha,Express,johnny-five和node编写testing时的菜鸟错误

你好,我试图学习一些使用快递,摩卡,柴和约翰尼五testing驱动开发。 所以我写了这个可以打开和closuresLED的小应用程序。 该应用程序的工作,但我的testing失败 有人能告诉我在testing中我做错了什么吗? 谢谢 npm test的输出是 > blink@1.0.0 test /Users/me/Documents/johnny-five/blink > mocha –reporter spec 1435257445439 Looking for connected device j5 .on() 1) Should turn a led on .off() ✓ Should turn a led off 1 passing (13ms) 1 failing 1) j5 .on() Should turn a led on: AssertionError: expected undefined to equal 1 at […]