Tag: mocha

Node.js – 为什么在使用摩卡和僵尸进行testing时会出现泄漏?

我试图让僵尸工作与摩卡,但除非我使用摩卡–ignore – 泄漏命令选项,我的testing总是失败,错误: Error: global leaks detected: k, i, name, chars, char 我的testing看起来就像这个线程中所解释的: Mocha和ZombieJS 我希望我可以在那里发布我的问题,但作为一个新手,我不能评论的线程,只问一个新的问题。 你有什么想法,为什么我得到这些泄漏? 我正在使用摩卡1.0.3和僵尸1.0.0。

摩卡js断言悬挂使用诺言?

"use strict"; let assert = require("assert"); describe("Promise test", function() { it('should pass', function(done) { var a = {}; var b = {}; a.key = 124; b.key = 567; let p = new Promise(function(resolve, reject) { setTimeout(function() { resolve(); }, 100) }); p.then(function success() { console.log("success—->", a, b); assert.deepEqual(a, b, "response doesnot match"); done(); }, function […]

res.should.have.status给我错误

我是新来的摩卡和should.js。 我试图检查响应的状态,但它给了我TypeError: Object #<Assertion> has no method 'status'代码是这样的: describe('Local signup', function() { it('should return error trying to save duplicate username', function(done) { var profile = { email: 'abcd@abcd.com', password: 'Testing1234', confirmPassword: 'Testing1234', firstName: 'Abc', lastName: 'Defg' }; request(url) .post('/user/signup') .send(profile) .end(function(err, res) { if (err) { throw err; } res.should.have.status(400); done(); }); }); 我也注意到,虽然我已经声明var should […]

如何在Travis CI的一个项目中运行Node.js和Rubytesting

我有一个包含多个组件的报表,其中大多数在JavaScript(Node.js)和一个用Ruby(Ruby on Rails)编写的组件。 我想有一个.travis.yml文件触发一个构build,运行每个组件的所有testing。 根据Travis CI Google Group主题 ,目前还没有官方的支持。 我的目录结构如下所示: . ├── buildserver ├── core ├── extensions ├── webapp ├── Vagrantfile ├── package.json ├── .travis.yml └── Makefile 我想能够运行特定版本的Ruby(2.2.2)和Node.js(0.12.2)。 我已经有了一个make目标,所以make test在每个子目录下运行适当的testing套件。

Cloud9中的Mochatesting中的“未声明的variables”警告

我是node.js和unit testing框架Mocha的新手,但是我已经在cloud9 IDE中创build了一些testing,以了解它是如何工作的。 代码如下所示: var assert = require("assert"); require("should"); describe('Array', function(){ describe('#indexOf()', function(){ it('should return -1 when the value is not present', function(){ assert.equal(-1, [1,2,3].indexOf(5)); assert.equal(-1, [1,2,3].indexOf(0)); }); }); }); describe('Array', function(){ describe('#indexOf()', function(){ it('should return the index when the value is present', function(){ assert.equal(1, [1,2,3].indexOf(2)); assert.equal(0, [1,2,3].indexOf(1)); assert.equal(2, [1,2,3].indexOf(3)); }); }); }); 如果我在控制台中键入mocha,testing会起作用,但IDE会在“describe”和“it”的行中显示警告,因为它说variables没有被声明(“未声明的variables”)。 我想知道我应该怎么做这些testing来避免这些警告。 […]

赶上摩卡和柴的超出范围的错误

我正在修改一个node.js库来支持真正的asynchronous操作。 我和摩卡和柴一起做了这个类似的testing。 it('should throw an error', function() { expect(function() { process.nextTick(function() { throw new Error('This is my error'); }); }).to.throw(Error); }); 问题是 – 由于nextTick – 错误被抛出它的范围,除了testing失败,摩卡也输出下面。 Uncaught Error: This is my error 构build这个testing的正确方法是什么?

如何使用gulp和mocha写入文件?

我有一个使用Mocha json记者的抽样任务。 我想写的JSON输出到一个文件。 将欣赏一些投入。 这是我的代码: var gulp = require('gulp'); var mocha = require('gulp-mocha'); var util = require('gulp-util'); gulp.task('myreport', function() { return gulp.src(['tests.js'], { read: false }) .pipe(mocha({ reporter: 'json' })) //how do I write this to a file? .on('error', util.log); });

摩卡与nodejs断言悬挂/超时断言(错误),而不是错误

我有这种摩卡testing: describe 'sabah', → beforeEach → @sabahStrategy = _.filter(@strats, { name: 'sabah2' })[0] .strat it 'article list should be populated', (done) → @timeout 10000 strat = new @sabahStrategy() articles = strat.getArticleStream('barlas') articles.take(2).toArray( (result)→ _.each(result, (articleList) → // I make the assertions here // assert(false) assert(articleList.length > 1) ) done() ) 问题是,每当我assert(false) ,testing挂起,直到超时,而不是给一个断言错误,为什么? 编辑: 例如,如果我有这两个testing it […]

为节点模块映射path,用于unit testing

客户端我用SystemJS将模块path存到模块中,像这样 var systemJsConfig = { baseURL: "./", defaultJSExtensions: true, map: { 'root-components': 'applicationRoot/rootComponents' } }; 所以require('root-components/foo'); 将映射到applicationRoot/rootComponents/foo 。 问题是,如果我用require('root-components/foo');运行一个模块require('root-components/foo'); 在摩卡,节点不知道这个path是什么意思。 是否有一个理想的方式来完成在Node中的path映射? Proxyquire能胜任这个吗? 我阅读他们的文档,但没有发现任何迹象表明它是。 这只是unit testing,所以我很高兴任何解决scheme使用任何forms的党的实用程序。

找不到模块'./lib/should'

我有一个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); }) }) }) 当我运行它我得到错误 Error: Cannot find module './lib/should' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at require (module.js:380:17) at Object.<anonymous> (/home/ritesh/projects/passport-topcoder/node_modules/should/index.js:2:18) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load […]