Tag: 摩卡

在节点中运行时,使摩卡“使用严格”

在节点上运行时,有没有办法让Mocha在严格模式下运行testing? 通常情况下,您可以通过运行node –use_strict在节点中启用此node –use_strict 。 有没有办法为mocha做同样的事情?

Node.js摩卡进程(_mocha)不会在CTRL-C时退出

当mochatesting需要一段时间才能完成时,按CTRL-C退出mocha命令,但不退出testing运行器“_mocha”,testing继续。 有人知道这是否由devise? /* * test/mocha-kill-test.js */ describe("Mocha Timeout Test", function() { this.timeout(10e3); it("should exit when hitting CTRL-C", function(done) { var count = 0; var timer = setInterval(function() { if (count++ < 10) { console.log(" WAIT " + count); } else { console.log(" DONE"); clearInterval(timer); done(); } }, 1e3); }); }); 此testing将运行10秒钟,然后退出。 如果你试图用CTRL-C从terminal中断它(或者发送一个SIGINT),testing运行器将继续运行,你会在shell中看到类似的东西。 shell> mocha test/mocha-kill-test.js […]

Zombie.js pressButton长callback延迟

我一直试图通过使用一堆console.logs来解决这个问题,仍然无法弄清楚为什么这些加载时间如此之长。 所以我在我的摩卡unit testing文件中的beforeEach中有下面的代码。 browser.fill('email', 'test1@test.com'); browser.fill('password', 'testtest'); browser.pressButton('Login').then(function () { console.log("#100 – "+ new Date().getTime()); done(); }); 在这种情况下按下button将有一些redirect,然后最后显示仪表板页面。 在该HTML文件的底部,我有以下代码。 <script> $(document).ready(function () { console.log("#200 – "+ new Date().getTime()); }); </script> 所以在运行testing后,如果我把#100之后的值减去 #200之后的值总是大约5000-6000。 因为#200总是在#100之前打印5-6秒。 我不明白为什么加载页面之后需要额外的5-6秒才能调用Zombie.js来调用callback函数。 Zombie.js在加载页面后是否有一些等待或延迟? 还有什么可能导致页面加载和Zombie.js调用该callback函数之间5-6秒的延迟? 编辑我现在有这个相同的问题,但像一个50000毫秒。 这真是在我所有的testing中快速加起来的。 我仍然无法弄清楚为什么会发生这种情况。 编辑2 如果我添加browser.debug()到我的testing它最后打印下面。 它还打印了很多其他的东西,但总的来说很快。 我认为以下可能是问题。 只是不知道为什么这样做或如何解决它。 zombie Fired setInterval every 5000ms +11ms zombie Fired setInterval every 5000ms […]

用grunt摩卡避免需要(../../../ ..)相对path

在进行unit testing时,我倾向于在我的项目结构顶部有一个名为test的目录,目录结构模仿要testing的源代码。 但是,例如,这些目录可能会变得很深 app/src/js/models/User.js 也许在一个testing中 test/app/src/js/models/User.js 现在,当我想包含User.js模块时,我使用require('../../../../../app/src/js/models/Users.js') ,这非常麻烦。 理想情况下,我想使用require('/app/src/js/models/User.js')或者甚至require('User.js') 。 这可能吗? 我正在使用grunt-mocha-test ,但是我认为这个问题是一个更一般的问题。

用jenkins运行量angular器testing抛出“testing`标题”应该是一个“string”,但“function”被给予代替。

所以这是一个有点头痛的人。 如果我从Jenkins作业运行我们的量angular器e2etesting,则失败: [10:23:53] I/local – Starting selenium standalone server… [10:23:53] I/launcher – Running 1 instances of WebDriver [10:23:54] I/local – Selenium standalone server started at http://10.0.0.5:43412/wd/hub [10:23:56] E/launcher – Error: Error: Test `title` should be a "string" but "function" was given instead. at new Test (/var/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node_5.0.0/lib/node_modules/mocha/lib/test.js:24:11) at context.it.context.specify (/var/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node_5.0.0/lib/node_modules/mocha/lib/interfaces/bdd.js:84:18) at /var/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node_5.0.0/lib/node_modules/protractor/node_modules/selenium-webdriver/testing/index.js:95:14 at context.xit.context.xspecify.context.it.skip (/var/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node_5.0.0/lib/node_modules/mocha/lib/interfaces/bdd.js:103:15) at […]

使用时,testing不显示通过

我第一次testing我写一个testing用例 var should = require("should") describe('Array', function(){ describe('#indexOf()', function(){ it('should return -1 when the value is not present',function(){ [1,2,3].indexOf(5).should.equal(-1); [1,2,3].indexOf(0).should.equal(-1); }) }) }) 它给我0通过 0 passing (1ms) 但为什么它应该显示1通过

我应该如何使用摩卡和mongoose?

运行testing时,我一直在save()方法中发生错误。 var User = require('../../models/user') , should = require('should'); describe('User', function(){ describe('#save()', function(){ it('should save without error', function(done){ var user = new User({ username : 'User1' , email : 'user1@example.com' , password : 'foo' }); user.save(function(err, user){ if (err) throw err; it('should have a username', function(done){ user.should.have.property('username', 'User1'); done(); }); }); }) }) }) 这里是错误的: […]

Node.js,Mocha,使封闭的全局variables可用

我目前正在使用Node设置一些摩卡testing,一般来说,它们都可以工作。 我现在遇到了一个我无法解决的问题。 我有一个JS文件,其中包含以下内容:MyClass.js( class MyClass + constructor: ->常规CoffeeScript输出constructor: -> ) 编辑:这是浏览器代码,我只是想使用节点来testing它。 (这甚至是可取的?) (function() { window.MyClass = (function() { function MyClass() { // Do something cool here } return MyClass; })(); }).call(this); 我现在在我的testing文件中需要MyClass.js。 一旦我运行它,它直接抛出一个错误 TESTFILE: var myclass = require('MyClass.js'); … describe('MyClass', function() { … }); 错误: ReferenceError: window is not defined. 到目前为止,我明白为什么会发生这种情况,Node中不存在窗口。 但我不能想出一个解决scheme。 我其实并不需要真正的window对象,所以我认为嘲笑它就足够了。 但是这不是… var […]

如何使用摩卡生成多个报告?

我想要有以下报告: 覆盖 规范 的xUnit 所有在我的咕噜声中执行的一个摩卡执行 目前 – 我必须运行testing3次,每次生成一个不同的报告(!)。 所以我用2个configuration的grunt-mocha-test (只有记者不同)(一次xunit-file和一次spec)。 然后我又有grunt-mocha-istanbul再次运行testing,并生成覆盖报告。 我试过使用 { options: { reporters : ['xunit-file', 'spec'] } } 对于grunt-mocha-test ,至less把它降到2,但这并不是工作。 阅读grunt-mocha-istanbul文档,我似乎无法find关于reporterconfiguration的任何信息。 我该如何解决这个问题?

在摩卡testing中使用Superagent / Supertest和Express app

我正在尝试使用Mocha为我正在开发的REST API编写testing。 我发现Superagent让我做HTTP请求。 我正在使用一个Express应用程序,我将它传递给Superagent,但是当试图以这种方式传递Express应用程序来运行这些testing时,我得到关于Mongoose的奇怪错误。 这是我的testing代码: var // Node modules mongoose = require('mongoose') , async = require('async') , should = require('should') , request = require('superagent') , app = require('../../app_mocked') , Link = mongoose.model('Link') request = request(app) describe('Links resource', function () { var userId = '50dc81654dca01006b000005' , linkId , sampleLink = { 'uri': 'http://test.com/', 'meta': { 'title': […]