Tag: chai

即使我的摩卡testing用例正在使用,eslint仍然警告它?

我使用摩卡和chai.should断言库来unit testing我的OSS npm模块。 但是eslint [v3.18.0 ^]会在代码中的should声明中警告它没有被使用 const should = chai.should(); Lint警告 '应该'被分配一个值,但从来没有使用。 我们有摩卡作为.eslintrc的环境。 尽pipe在我的testing文件中有至less七个断言语句,但是下面的“应该”在这些语句中出现这个警告。 return sampleModule.getSomeFunction('dummy_accesss_token', 'dummy_event_id').should.eventually.be.eql([]); 我知道下面这个问题,谈到其他断言陈述,这是从来没有声明,而答复[甚至没有被声明为答案]查询有人创造了一个插件来克服这一点。 但我的基本前提是,这不是一个在eslint中的错误? 至less“应该”应该:-)不要被标记,因为它被用于代码[在我的情况多次]。

摩卡,nodejs承诺testing无法完成,因为缺乏完成

我试图运行一个承诺的testing,但testing失败,认为它超过超时限制,并build议确保我已经完成的条款。 这是我的testing代码的一部分: $configurations .updateConfiguration(configurations_driver.NOT_VALID_MODEL) //invalid model .then(function () { done(new Error("Expected INVALID_MODEL error but got OK")); }, function (error) { chai.assert.isNotNull(error); chai.expect(error.message).to.be.eq("INVALID_MODEL_ERROR"); chai.expect(error.kind).to.be.eq("ERROR_KIND"); chai.expect(error.path).to.be.eq("ERROR_PATH"); done(); }) .catch(done); }); 我已经完成了所有的子句,所以我不知道在testing中是否遗漏了某些东西,或者结构是错误的。

节点摩卡柴asynchronous – 一切都传递,即使它应该失败

我试图教自己使用一个testing框架来自动化testing,而不是手动完成。 经过一些试验和错误,我终于得到了unit testing开始传递…但现在,我的问题是一切都传递,不pipe是否应该。 目前我有以下代码: describe('create {authName, authPW}', function() { it('no name', function() { init({ path: ':memory:', callback: function() { var arg; arg = {}; //arg['authName'] = 'Name'; arg['authPW'] = 'Pass'; arg['callback'] = function(r) { // r.should.equal('create error'); r.should.equal('foobar'); done(); }; create(arg); } }); }); }); 正如你所猜测的那样… r不应该等于'foobar' 我在这里做错了什么?

Chaivariables不是由Karma / Grunt加载的

我不能让chai在业力/咕噜声中承诺。 运行grunt test或karma test/karma.conf.js时,出现以下错误: PhantomJS 1.9.8 (Mac OS X 0.0.0) ERROR ReferenceError: Can't find variable: chai at /Users/isaac/Sites/ChessGame/node_modules/chai-as-promised/lib/chai-as-promised.js:19 这看起来和这个问题类似,但是我正在承担起这个问题,而不是sin-cha。的。 我已经validation了node_modules/chai/chai.js存在。 这是我的package.json文件: { "name": "chessgame", "private": true, "devDependencies": { "angular-mocks": "^1.4.3", "chai": "^3.2.0", "chai-as-promised": "^5.1.0", "chai-things": "^0.2.0", "grunt": "^0.4.5", "grunt-angular-templates": "^0.5.7", "grunt-autoprefixer": "^2.0.0", "grunt-concurrent": "^1.0.0", "grunt-contrib-clean": "^0.6.0", "grunt-contrib-compass": "^1.0.0", "grunt-contrib-concat": "^0.5.0", "grunt-contrib-connect": "^0.9.0", "grunt-contrib-copy": "^0.7.0", "grunt-contrib-cssmin": […]

testingMicrosoft Bot Frameworkasynchronous回复

我正在使用Mocha和Chai(BDD模式)testing我的Bot。 我想从事件发射器收听,看看我收到了哪些回复,并根据我发送的文本判断是否有意义。 我的testing通常遵循这个模式: beforeEach(function (done) { bot = require('myModule').textBot; bot.removeAllListeners('reply'); done(); }); describe('', function(){ it('', function (done) { bot.on('reply', function (message) { assert.include(message.text.toLowerCase(), ''); done(); }); bot.processMessage({text: 'message_that_will_trigger'}); }); }); 我有多个描述和多个我的testing。 有时,错误的回复回复会触发回复(即使我重置beforeEach上的所有callback),所以testing将会失败。 如果我只运行特定的testing。 他们通过。 这是testing这个最好的方法吗? 我该如何解决这个问题?

unit testingExpress Middleware的正确方法

我有一个Express中间件,它被设置为在我的服务器的所有POST请求中检查有效的Content-Type头,这个中间件的代码如下: import * as STRINGS from "../Common/strings"; function ContentTypeValidator(req, res, next) { let contentHeader = req.get("content-type"); if(!contentHeader) { res.status(400).send(STRINGS.ERROR_CONTENT_TYPE_MISSING); } else { if(contentHeader.toLowerCase() !== "application/json") { res.status(415).send(STRINGS.ERROR_CONTENT_TYPE_UNSUPPORTED); } else { next(); } } } export default ContentTypeValidator; 我为我的TDD使用了mocha , chai和node-mocks-http ,当next()不会被调用时,我的问题围绕着testing, res.send()将为我处理这个请求的结束。 it("Should return 200 for valid Content-Type header", (done) => { req = nodeMocks.createRequest({ […]

ChaiJs不出现在Phantomjs-node injectJS的窗口中

我正在尝试将一些脚本注入到使用phantomjs-node桥加载到PhantomJs中的页面中。 当我将MochaJs注入页面时,我可以评估和window.mocha对象可用。 但是当我注入chaiJs时, window.chai对象不可用。 我已经validation了injectJs调用将true状态传递给了callback,表明脚本被成功注入了,并且我也证实了window.chai和window.mocha在注入之后立即可用: http: //plnkr.co/edit/gMzjavJqpNDNeYipmBHG?p=preview 我甚至尝试使用page.includeJs('http://cdnjs.cloudflare.com/ajax/libs/chai/1.10.0/chai.min.js')来确保在cloudflare cdn版本中没有差异我有的npm安装版本,仍然不能正常工作。 我究竟做错了什么? page.injectJs(nodeLibDir + '/chai/chai.js', function(){ //page.injectJs(nodeLibDir + '/mocha/mocha.js', function(){ page.evaluate(function(){ //window.callPhantom(window.mocha.constructor.name); window.callPhantom(window.chai.version); }, function(){ console.log('finished'); page.close(); res.json({status: status}); res.end(); }); });

mongoose模式unit testing失败与前保存挂钩

使用“预保存”mongoose钩似乎会导致我的unit testing超时(超过2000毫秒的错误)。 当我注释掉预保存钩子时,unit testing工作正常……但是当包含pre-save-hook时,testing超时并且不返回任何特定的错误消息。 任何想法可能是错的? 模型(User.js) var mongoose = require('mongoose'); var bcrypt = require('bcrypt'); var Schema = mongoose.Schema; var userSchema = new Schema({ "auth": { "local": { "email": String, "password": String, } }, "userProfile" : { "firstname" : {"_default": String}, "lastname" : {"_default": String}, "username": String, "email" : String, } }); userSchema.method('genHash',function(password){ return bcrypt.hashSync(password, bcrypt.genSaltSync(9)); […]

摩卡+ chai + jsdom-不能加载自定义模块目录

我正在使用一个多入口的应用程序,它大量使用通用组件,我从webpack中的resolve部分加载它(请参阅webpack文件) webpack文件 resolve: { extensions: ['', '.js', '.css', '.scss', '.jsx', '.json'], modulesDirectories: ['node_modules', 'common'] } 但问题是,当我要testing该组件,它不能从通用文件夹加载目录,因为我没有定义它作为模块目录,所以有没有办法加载自定义模块目录在testing环境

使用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 […]