Tag: 摩卡

用摩卡柴和Stormpath

我的谷歌福可能失败了我,但我正在考虑为使用Stormpath进行身份validation的快速应用程序构buildunit testing。 所以典型的路线看起来像这样; app.get('/api/user', stormpath.loginRequired, userApi.get); 在这种情况下,我将如何使用像Mocha + Chai这样的testing框架?

Mocha-aure-reporter不使用节点js

当我用mocha-alure-reporter运行我的testing时,我遇到了问题,testing用mocha成功运行,但是mocha –reporter mocha-aure-reporter返回以下错误 > notifications-api@1.0.0 test /app > mocha –reporter mocha-allure-reporter 2016-11-15T06:13:26.762Z – info: Notification API up and running on port 4000 2016-11-15T06:13:26.773Z – error: Tue, 15 Nov 2016 06:13:26 GMT uncaughtException 2016-11-15T06:13:26.775Z – error: TypeError: test.currentRetry is not a function at Runner.<anonymous> (/app/node_modules/mocha-allure-reporter/index.js:29:19) at emitOne (events.js:77:13) at Runner.emit (events.js:169:7) at next (/app/node_modules/mocha/lib/runner.js:517:10) at Runner.runTests […]

伊斯坦布尔与巴贝尔有什么关系?

我正在尝试将代码覆盖范围添加到从ES2015转换的现有库中。 我似乎在做一切正确的事情。 我的生成文件读取 test: .FORCE export NODE_ENV=test babel *.js –out-dir lib nyc mocha 而我的babelrc读取 { "presets": ["es2015"], "sourceMaps": true, "env": { "test": { "plugins": ["istanbul"] } } } 而我的package.json包括 "nyc": { "include": [ "**/*.js" ], "require": [ "babel-register" ], "sourceMap": false, "instrument": false } 然而,我的testing运行后,输出简单地读取: ———-|———-|———-|———-|———-|—————-| File | % Stmts | % Branch | % […]

尝试在摩卡中使用asynchronous/等待

我想在摩卡中使用asynchronous/等待,以使我的testing。 我已经阅读了很多文章,但是我没有find解决scheme。 我已经安装了所有的babel模块来编译代码,但是它不起作用。 这里是我的代码里面的“testing”文件夹: import test from 'mocha' import 'babel-polyfill' import { expect } from 'chai' import { assert } from 'chai' import utils from '../lib/utils' describe('long number', function () { it("Sample", mochaAsync(async () => { var x = utils.longNums(0); expect(x).to.equal(5000); })) }) 这里是我的package.json,我使用所有的babel依赖和插件,我已经阅读我必须安装,我的testing脚本,我build议摩卡使用巴贝尔transpiling { "name": "pos_lisa-test", "version": "1.0.0", "description": "pos lisa test", "main": "index.js", […]

testing节点,摩卡和柴(应/ bdd语法)

上下文 我是一个JavaScript的爱好者,并把我的项目到一个新的水平,我试图在BitBucket中设置一个pipe道,将运行我的unit testing(和稍后做其他事情)。 我已经使用Mocha和Chai进行testing,但是我在浏览器中使用了一个设置依赖关系并运行testing的html页面。 问题 我面临的问题是,我不能让should语法在节点中工作,而我之前在浏览器中已经有工作testing。 should作为柴图书馆的一部分。 我使用最less的代码初始化了一个新的项目,但是在这里它也不起作用: should简单地不分配。 package.json ,包括摩卡和柴,并build立摩卡进行testing。 { "name": "testtest", "version": "1.0.0", "description": "Minimal, complete and verifiable example", "main": "index.js", "dependencies": {}, "devDependencies": { "chai": "^4.0.1", "mocha": "^3.4.2" }, "scripts": { "test": "mocha -u bdd" }, "author": "GolezTrol", "license": "ISC" } test / test-foo.js ,包含testing。 我添加的唯一的东西是require的第一行。 之前,浏览器包含了这个文件,Foo是全球的。 我回应道,给了我5个口,应该给我不明确的。 var Foo = […]

Sinon TypeError:尝试包装运行多个脚本时已包装的<method>

在使用sinon.js(和mocha)进行testing时出现错误。 当我通过npm运行所有的testing脚本时发生错误,但是当我通过IDE运行单个脚本时不会发生错误。 单独运行testing脚本工作正常,testing通过。 即我有一个目录中有几个testing脚本。 当我自己运行一个脚本时,testing通过。 当我在目录中运行所有的脚本时,tess失败,出现错误: testing将失败 TypeError: Attempted to wrap getVariable which is already wrapped 而其他testing失败: TypeError: Cannot read property 'restore' of undefined 两个testing脚本都以相同的代码开始: const assert = require('assert'), sinon = require('sinon'); global.context = { getVariable: function(s) {} }; var contextGetVariableMethod; beforeEach(function () { contextGetVariableMethod = sinon.stub(context, 'getVariable'); }); afterEach(function () { contextGetVariableMethod.restore(); }); 我猜摩卡同时运行两个testing? […]

我的摩卡testing分开工作,但一次运行全部失败

这可能与asynchronous代码有关,但我不知道是什么。 当我将它们分开时,两者都通过: mocha test/models.coffee和mocha test/login.coffee 但是, describe 'saving another user with same username', ->与npm test一起运行testing失败。 我想数据库得到清除,因为它正在运行该步骤,所以它节省了,而不是产生一个错误,因为它应该是一个独特的价值。 另外:在这个软件testing方面我是非常新的,如果有人有任何提示,或者想批评我公然的错误,随时给我发电子邮件(检查我的个人资料) 谢谢!! 这里是我的两个testing文件(coffeescript): /test/models.coffee should = require 'should' {User} = require '../models' # function to find our test user, John Egbert findJohn = (cb) -> User.findOne {'public.username': 'john'}, (err, john) -> throw err if err cb(john) before (done) -> […]

我如何断言一个函数被调用?

我有一个山羊类: class Goat constructor: (@headbutt) -> @isCranky = true approach: -> if @isCranky @headbutt() 我想写一个摩卡testing来声明,如果isCranky为true并调用方法,则调用headbutt()。 我能find的唯一解释是在Ruby中。 试着翻译它,但失败了。 我怎样才能断言正确的function被称为? 我认为我可以用一种拙劣的方式解决问题,但宁可学习正确的方法。 build议?

优雅的方法来过滤标准输出内容文件? 或者关掉摩卡的微调?

我正在使用mocha -w进行连续testing。 我遇到了另一个lib的套接字连接的bug,只有在使用mocha -w一段时间才会发生。 我需要捕获指向console.logdebugging输出到一个文件,以便大量的数据可以被search和过滤用于故障排除。 然而,摩卡的“看”微调正在阻碍。 当我尝试使用Windows Power Shell,GitHub的Git Shell或DOS将stdoutredirect到一个文件时: mocha -w >> log.txt 我从animation的微调器中获得这样的数据: [0G [96m | [90m观察[90m观察[0m [90m观察[0m [0G [90m观察[90m观察[90m观察[ [90m观察[90m观察[0m [90m观察[0m [0G [90m观察[90m观察[90m观察[ [90m观察[90m观察[0m [90m观察[0m [0G [90m观察[90m观察[90m观察[ [90m观察[90m观察[0m [90m观察[0m [0G [90m观察[90m观察[90m观察[ [90m观察[0m [0G [96m / [90m观察[0m [0G [96m- 这个SO问题build议制作Mocha的副本,然后play()方法。 然而,通过使用黑客版本的摩卡来尝试排除可能是摩卡缺陷的问题并不理想。 所以现在看来​​是扩展我的shell知识和node.js知识的好时机。 有没有一种优雅的方式来做以下任何事情? 当它们以animation控制字符开始时,过滤掉文件? 防止摩卡渲染微调文本? (似乎没有任何标志, 像这样的文档和bug ,从来没有build议翻转解决scheme的标志)

导出所需的相同对象会混淆摩卡

我正在使用摩卡运行unit testing的节点应用程序。 当我运行这个命令时: mocha –compilers coffee:coffee-script –reporter spec ./test/unit/*-test.coffee 我得到这个错误: ERROR: Unknown option –compilers 看来摩卡是混乱的,因为它肯定有一个编译器选项。 当我添加一个新的文件到项目时,这个错误开始发生。 这是我可以得到摩卡生成的唯一输出。 – 破坏者什么都不做。 比方说,我有一个名为人安装的软件包。 我想全局configuration这个包,这样我就可以在我的项目的任何地方导入configuration的对象。 为此,我导入人员,将其configuration为驱动程序,然后重新导出。 但是,当我导入它(无论是在Car.coffee或Car-test.coffee),摩卡失败,出现上述错误。 Driver.coffee driver = require 'person' driver.setSkill "Drive" module.exports = driver Car.coffee driver = require './driver' … Car-test.coffee driver = require '../../src/driver' … 请注意,这工作正常,如果我只是用咖啡编译和运行节点项目。 这里没有问题导入。 但是当我用摩卡运行,如果我导入文件失败。 我无法确定这个错误。 这看起来就像摩卡的一个错误,但也许我正在做一些“坏”的东西,通过导出相同的对象,我导入,节点只是更宽容? 我正在使用最新版本的摩卡(1.13.0)。 谢谢! 编辑: 这不能解决这个错误,而且不是理想的语法: person […]