Tag: 摩卡

运行摩卡咕噜声 – 当testing失败时放弃

我正试图学习这个自动unit testingmalarkey。 我想使用Grunt自动运行我的Mochatesting,并将testing结果输出到一个文件。 据我所知,我需要使用grunt-mocha-cov 。 我有这样的工作:当testing通过Grunt写出结果文件确定。 但是,当其中一个失败,我得到这个: Running "mochacov:all" (mochacov) task Warning: Use –force to continue. Aborted due to warnings. 并没有创build文件。 谁能告诉我哪里出错了? 我的项目是这样组织的: 我的testing文件夹包含一个文件,test.js,看起来像这样: var chai = require("chai"), assert = chai.assert, expect = chai.expect; var foobar = { sayHello: function() { return 'Hello World!'; } } describe('Foobar', function() { describe('#sayHello()', function() { it('should work with […]

用mochatestingnode.js – Newbie

我已经开始在我的JS项目中实现TDD。 我为此目的实施了摩卡。 由于这些是我所做的第一步: 安装了node.js 为我的项目在全球和本地安装了摩卡。 写了package.json设置依赖关系。 写了makefile。 写了.gitignore以避免上传node_modules文件夹。 文件夹结构 项目 – js —- filetotest.js – test —- test.js 我想要做的就是运行命令make test,以便在testingfiletotest.js文件的test.js中运行testing。 我读了关于使用导出的node.js方法。 但有没有办法将文件包含在testing套件中? 我被困在这里,我认为我的怀疑更多是关于概念而不是科技的东西。 会很感激你的帮助。 澄清一下我想做什么: https : //nicolas.perriault.net/code/2013/testing-frontend-javascript-code-using-mocha-chai-and-sinon/ 我想通过命令行得到类似的结果。 非常感谢, 吉列尔莫

摩卡不会在更改后重新运行我的testing

使用testing环境 chokidar (用观察者 chokidarvariables触发testing文件的变化), node.js (在浏览器中输出testing结果), mocha+chai (testing套件), 使用自定义记者(如编程使用摩卡中所述) 当testing文件被改变时, 观察者捕捉事件,并且应该重新运行testing。 问题 :我的testing只执行一次! 当试图再次运行我的testing(当文件第二次在磁盘上改变时), mocha不会像第一次那样重新处理testing。 我怀疑我应该重置一些内部运行属性,但看在摩卡github库,我似乎没有find正确的方法来调用。 请注意,我的记者“class”只收到了第二个观察员wakup上的mocha runner.on(“end”,…)的一个事件。 watcher.on('change', function(path, stats) { // … console.log('—–File ' + path + ' has been changed ' + "[" + stats.size + "b]" ); Mocha = require('mocha'); Mocha.prototype.printFiles = function(){ console.log("Existing files = "); console.log( this.files ); return […]

Sonarqube没有检测到使用摩卡生成的LCOV报告

我已经创build了一个简单的项目,使用Node.js,mocha生成代码覆盖率和unit testing的报告,如下所示: mocha -R lcov –ui tdd > coverage/coverage.lcov mocha -R xunit –ui tdd > coverage/TEST-all.xml 使用声纳运动员生成的报告并不反映Sonarqube的报道。 使用声纳实例主设备附带的LCOV的样本testingJavaScript项目在Sonarqube中显示0%的代码覆盖率。 声纳的属性如下: sonar.language=js sonar.sourceEncoding=UTF-8 sonar.tests=test sonar.javascript.jstestdriver.reportsPath=coverage sonar.javascript.lcov.reportPath=coverage/coverage.lcov sonar.dynamicAnalysis=reuseReports 期待有关如何解决此问题的投入,并使SonarQube能够报告现有LCOV报告的覆盖范围。 谢谢, 新

使用SailsJS / Node,Mocha,Supertest进行authentication的会话存储

我有一个SailsJS设置,并使用Mocha / Supertest / Superagent组合来运行unit testing。 我search了四周,阅读supertest,现在它如何扩展superagent.agent('url')以存储会话和cookie。 我知道我/运动员/login和/运动员/当前路线正在工作,因为我可以使用邮差testing他们,他们返回正确的值。 然而,在testing时,我在login时获得了200个状态,但是404 /运动员/当前状态 这是我目前的工作: 1.摩卡testinglogin和validation用户login会话 var should = require('should'), assert = require('assert'), request = require('supertest'); it('/athlete/login should return 200 and athlete on success', function (done){ var athleteStub = AthleteStub(), setPassword = athleteStub.password; Athlete.create(athleteStub, function(err, newAthlete) { var user = request.agent(sails.express.app); user .post('/athlete/login') .send({ 'email': athleteStub.email, 'password': setPassword }) […]

覆盖伊斯坦布尔和摩卡/柴的function

我无法理解如何unit testingfunction,以便伊斯坦布尔会考虑它们。 举一个非常简单的例子,我创build了这个math模块: var add = function( one, two ){ return one + two; } module.exports = { add: add }; 和基本的unit testing: var chai = require('chai'); var expect = chai.expect; describe('add() method', function(){ it('should do math', function(){ expect( some.add(1, 1) ).to.equal(2); }); }); 伊斯坦布尔的报告给了我这些结果: 发言:66.67%(2/3) 分支机构:100%(0/0) function:0%(0/1) 行数:66.67%(2/3) 忽略:无 如果简单地testing调用函数的结果不算作覆盖率,那么在unit testing无法访问的函数范围内,如何testing此代码?

删除后再保存mongoose文件

我尝试使用摩卡unit testing我的restify node.js-app并且不嘲笑mongodb数据库。 由于有些testing会改变数据库,所以我想在每次testing之前重置它的内容。 在我的testing中,我也需要访问我正在创build的mongoose文件。 因此我必须在beforeEach钩子之外定义它们(参见下面的user文档)。 但是,清空数据库之后似乎不可能再次保存文档。 下面是我想到的一个简单的例子。 在这种情况下,第二个testing将失败,因为user不会再被保存。 如果我删除了第一个testing, beforeEach只能调用一次,一切都很好。 另外,如果我在beforeEach钩子里面定义user ,它也可以工作。 所以我真正的问题:是否有可能解决这个问题,并删除后保存文件第二次? 或者你有任何其他的想法,我怎么可以在beforeEach钩子内重置数据库? 在每个testing用例之前进行相同的数据库设置的正确方法是什么? var mongoose = require('mongoose') var Schema = mongoose.Schema var should = require('should') var flow = require('async') var UserSchema = new Schema({ username: {type: String, required: true, unique: true}, password: {type: String, required: true}, name: {type: String, default: ''} }) […]

VersionError:仅在(Mocha)testing中发现匹配的文档错误

我已经阅读了其他问题/答案的人有版本的关键,但由于某种原因,我不明白为什么这具体发生在我的情况。 所以我有以下摩卡testing: it('should be able to save one job', function (done) { Promise.join(user.saveAsync(), company.saveAsync(), function (savedUser, savedCompany) { user = savedUser[0]; user.jobs.push(job); user.saveAsync() .spread(function (savedUserWithJob) { user = savedUserWithJob; user.jobs.should.have.length(1); done(); }) .catch(function (err) { done(err); }); }); }); 这一切都很好,并通过。 即使在运行时我也没有任何其他问题。 现在当我尝试在第一个之后再次运行相同的testing时, it('should be able to save one job', function (done) { ….. }); it('should […]

Nightmare.js和代码覆盖率

简洁版本: 我无法从我使用nightmare.js和mocha写的testing中看到代码覆盖率。 到目前为止,我已经尝试过使用伊斯坦布尔和_mocha。 大版本: 我有一个小项目: /public/index.html <html lang="en"> <head> <meta charset="UTF-8"> <title>My Website</title> <script src="./js/hello.js"></script> </head> <body> <h1>My Website</h1> </body> </html> /public/js/hello.js window.hello = function hello(){ return 'world'; }; 该网站使用快递和永远运行。 当我试图使用nightmare.js来testing它。 /test/test.js var path = require('path'); var Nightmare = require('nightmare'); var should = require('should'); /*global describe */ /*global it */ describe('Simple demo', function () { […]

“没有听众检测到”validation错误mongoose和摩卡

我正在尝试为我的快速应用程序的POST函数设置unit testing。 我有以下两个领域简单的mongoose纲要,其中一个是必需的。 当我在validation/必填字段closures的情况下进行摩卡testing时,testing是正确的,但是当所需设置为true时,testing失败,出现以下错误: Uncaught: No listeners detected, throwing. Consider adding an error listener to your connection. ValidationError: Path 'title' is required 有任何想法吗? 正如你所看到的,我肯定已经满足了模式要求,并且包含了标题字段。 这里是我的testing下面:有趣的是,第一个testing似乎工作正常,只有当我试图发布,它会产生错误。 describe('Add one story to:\n\thttp://localhost:XXXX/api/stories', function () { var testStory = new Story( { title: 'Mocha C title', shortTitle: 'Mocha C shortTitle' } ); describe('Story object', function(){ describe('Save story object', function(){ […]