Tag: 摩卡

伊斯坦布尔的摩卡testing代码覆盖率

我正试图让伊斯坦布尔工作。 我在伊斯坦布尔运行结束时一直收到这个消息: 没有收集覆盖信息,没有写覆盖信息退出 我已经尝试了一切,我可以在网上find你可以看到: "scripts": { "start": "node ./bin/start.js", "test": "mocha test –no-timeouts", "debug_mocha": "node-debug –no-timeouts _mocha", "eslint": "eslint .", "jshint": "jshint –exclude ./node_modules .", "istanbul": "istanbul cover –include-all-sources –hook-run-in-context node_modules/.bin/_mocha — -u exports -R spec test/**/*", "istanbul2":"istanbul cover node_modules/.bin/_mocha — -u exports -R spec test/**/*", "istanbul1":"istanbul cover node_modules/.bin/_mocha — test/**/*", "istanbul0":"istanbul cover _mocha test/**/*.js", […]

摩卡失败断言造成超时

我正在开始使用NodeJS的摩卡testing框架。 成功断言工作正常,但如果断言失败,我的testing超时。 为了断言我已经尝试了应该和期望。 例如(asynchronous代码) it('should create new user', function(done){ userService.create(user).then(function(model){ expect(model.id).to.be(1); //created user ID done(); }, done) }); 在这里,如果模型id不是1,那么testing超时而不是报告失败的断言。 我确定我做错了什么。 感谢你的帮助。 谢谢!

在testing环境中运行摩卡testing?

我似乎无法告诉摩卡在testing环境中运行我的testing套件。 app.js app.configure('test', function(){ app.set('port', 3002); }); testing/ some-test.coffee app = require('../../app') process.env.NODE_ENV = 'test' describe 'some test', -> it 'should pass', -> 由于我需要的应用程序,当我运行testing,我期望看到 Express server listening on port 3002 而是我看到了 Express server listening on port 3000 在app.js的开发configuration块中设置不同的端口号 Express server listening on port [whatever port I set in development block in app.js] 我无法让我的testing在testing环境中运行。 有什么build议么?

在mocha的afterEach函数中获取testing名称

让我首先说我对node.js和mocha很新颖。 我开始使用tdd方法,我试图从beforeEach和afterEach函数中开始或者刚刚完成的testing,但是我没有运气(我主要对afterEach感兴趣)。 至less我无法想象一个干净利落的做法。 我唯一能想到的就是把testing和套件保存在一个variables中,然后在afterEach()上做一些匹配,看看哪个testing已经完成。 理想情况下,它说“testing名称”,我想有一些像suite.test.name suite('my test suite', function() { beforeEach(function () { console.log('test name'); }); test('first test', function (done) { var testarray = ['1', '3', '5', '7']; testarray.forEach(function(num, index) { console.log('num: ' + num + ' index: ' + index); }, done()); }); afterEach(){ console.log('test name'); } }

如何断言不为空?

我在JavaScripttesting非常新,我想知道如何在摩卡框架断言不为空。

如何使用数据编写摩卡咖啡发布请求testing以testing响应是否匹配?

问题:我如何在摩卡咖啡中写一个post请求testing来testing响应是否匹配? 响应只是一个urlstring,因为它是第三方服务的redirect。 工作示例有效载荷: curl -H "Content-Type: application/json" -X POST -d '{"participant":{"nuid":"98ASDF988SDF89SDF89989SDF9898"}}' http://localhost:9000/api/members member.controller.js // post方法 // Creates a new member in the DB. exports.create = function(req, res) { Member.findByIdAndUpdate(req.body.participant.nuid, { "$setOnInsert": { "_id": req.body.participant.nuid } }, { "upsert": true }, function(err,doc) { if (err) throw err; res.send({ 'redirectUrl': req.protocol + '://' + req.get('host') + '/registration/' […]

如何使伊斯坦布尔生成所有我的源代码覆盖?

目前伊斯坦布尔只是生成我的testing中使用的文件的覆盖率,这是可以的,但似乎打破了有些覆盖面的目的。 我没有伊斯坦布尔configuration,并通过npm test与以下脚本string调用它: $ istanbul cover _mocha — -R dot –check-leaks –recursive test/ 有没有办法为我所有的源代码生成覆盖率?

如何模拟mocha.js进行unit testing的依赖类?

鉴于我有两个ES6类。 这是A类: import B from 'B'; class A { someFunction(){ var dependency = new B(); dependency.doSomething(); } } 和B类: class B{ doSomething(){ // does something } } 我使用摩卡进行unit testing(与ES6的babel),柴和sinon,这真的很棒。 但是在testingA类时,我怎样才能为B类提供一个模拟类? 我想嘲笑整个B类(或所需的function,实际上并不重要),以便类A不执行真正的代码,但我可以提供testingfunction。 这就是摩卡testing现在的样子: var A = require('path/to/A.js'); describe("Class A", () => { var InstanceOfA; beforeEach(() => { InstanceOfA = new A(); }); it('should call B', () […]

运行testing之前清除testing数据库

在运行testing套件之前清理数据库的最好方法是什么(是否有npm库或推荐的方法)。 我知道before()函数。 我使用节点/快递,摩卡和续集。

如何在nodejs中模拟请求和响应来testing中间件/控制器?

我的应用程序有几个层次:中间件,控制器,pipe理器。 控制器接口与中间件接口相同:(req,res,next)。 所以我的问题是:我怎样才能testing我的控制器,而无需启动服务器,并发送“真正的”请求本地主机。 我想要做的是创build请求,响应实例为nodejs然后只是调用controllers方法。 像这样的东西: var req = new Request() var res = new Response() var next = function(err) {console.log('lala')} controller.get_user(req, res, next) 任何意见是高度赞赏。 谢谢! PS我想这样做的原因是,最后我想testing响应对象是否包含玉视图的正确variables。