Tag: nodeunit

断言库node.js?

node.js assert提供的unit testing断言非常有限。 即使在我写第一个testing之前,我已经创build了一些断言,因为很明显我会继续使用它们。 你能推荐一些好的断言库来testing常见的JavaScript情况(对象结构,对象类等)吗? 理想情况下,它应该很好地与nodeunit集成在一起(或者更好地扩展它的断言) – 我的断言不需要,我必须把它们作为一个额外的variables来test … 我见过的唯一一个是柴 。 你能说什么呢?

当在Nodeunit中使用Sandbox时,伊斯坦布尔的代码覆盖错误

我已经使用nodeunit编写了一堆testing来testing我的代码。 在这样做的时候,我想模拟被测代码所需的模块。 而不是改变代码,使其更容易与嘲笑testing,控制反转,当不需要,我改用了nodeunits沙箱function。 例 var nodeunit = require("nodeunit"); export.MyTest = { test1(test) { var fakeGlobals = { require: function(filename) { if (filename == "CoolUtil.js") { return { doit: function wasCool() { return true; } }; } else { return require(filename); } } }; var testSubject = nodeunit.utils.sandbox("ModuleUnderTest.js", fakeGlobals); test.equals(42, testSubject.doSomethingCoolUsingCoolUtil(), "Worked"); test.done(); } } 伊斯坦布尔给了我错误的报道数字。 […]

如何在coffeescript文件中使用node.js模块的“nodeunit”

我试图让一个coffeescript项目中的nodeunit模块工作,但似乎无法得到一个基本的testing运行。 这里是我的例子Coffeescript需要'nodeunit' test = true test2 = false exports.testSomething = (test) -> test.expect(1) test.ok(true, "this should pass") test.done() exports.testSomethingElse = (test2) -> test2.expect(1) test2.ok(false, "this should fail") test2.done() 不幸的是,当我运行'$ nodeunit example.coffee'时,我得到错误输出: example.coffee:4 exports.testSomething =(test) – > ^ module.js:296 throw err; 在Module.load(module.js:334:31)上的Object.js(module.js:408:10)上​​的Module._compile(module.js:397:25)处的SyntaxError:Unexpected token> (module.js:293:12)在/ usr / local / lib / node /usr/local/lib/node/nodeunit/lib/nodeunit.js:75:37的require(module.js:346:19) /usr/local/lib/node/nodeunit/deps/async.js:118:13位于/usr/local/lib/node/nodeunit/deps/async.js处的/nodeunit/deps/async.js:508:13 :/usr/local/lib/node/nodeunit/deps/async.js:507:9:134:9 任何人都可以帮助我简单的testing和运行在Coffeescript使用Node.js? 提前致谢

用mongoose对node.js进行unit testing的结构

我一直在开发与node.js几个月,但现在我开始一个新的项目,我想知道如何构build应用程序。 谈到unit testing时,我的问题就来了。 我将使用nodeunit编写unit testing。 另外我使用express来定义我的REST路由。 我想写我的代码访问数据库在两个“单独的”文件(他们会更多,显然,但我只是想简化代码)。 会有路线代码。 var mongoose = require('mongoose') , itemsService = require('./../../lib/services/items-service'); // GET '/items' exports.list = function(req, res) { itemsService.findAll({ start: req.query.start, size: req.query.size, cb: function(offers) { res.json(offers); } }); }; 而且,正如我在那里使用的一个项目服务只是用来访问数据层。 我这样做是为了testingunit testing中的数据访问层。 这将是这样的事情: var mongoose = require('mongoose') , Item = require('./../mongoose-models').Item; exports.findAll = function(options) { var query = […]

如何testing一个Grunt任务? 理解和最佳实践

理解如何编写复杂的Gruntfile.js并在testing中使用它,我有点Gruntfile.js 。 我是否正确使用Grunt? 我想问社区的帮助,并以另一种方式作出贡献。 我正在为Grunt写一个新的任务 ,并希望在Github和npm上为广泛的读者推出它。 我想为这个任务进行自动化testing(我想学习如何正确执行)。 我想testing不同的选项组合(现在大约15个)。 所以,我应该多次: 运行清理 运行我的任务设置下一个选项 运行testing并将选项对象传递给testing 一些非工作代码,以便更好地理解: Gruntfile: grunt.initConfig({ test_my_task: { testBasic: { options: { //first set } }, testIgnore: { options: { //another set } }, //… } clean: { tests: ['tmp'] // mmm… clean test directory }, // mmm… unit tests. nodeunit: { tests: ['test/*.js'] //tests code […]

Nodeunit:运行时/testing函数中抛出的错误是_silent_

使用NodeUnit的一个要点是编写新的函数并经常testing它们。 问题是,如果其中一个testing函数抛出一个错误(包括JS运行时错误),错误不会显示给用户。 这里是最简单的testing用例:(注意,abcd会导致运行时错误) exports.all = { one: function( test ){ test.done(); }, two: function( test ){ as( function( err, res ){ test.done(); }); }, } function as( callback ){ process.nextTick( function() { a = testMe(); callback( null, a ); }); } function testMe(){ abcde = 100; return 10; } 但是,testMe()可能是我正在开发的一个新函数。 一个未初始化的variables,或者任何东西 ,将会沉默。

Nodeunit test.throws似乎没有发现错误

我正在尝试为使用Nodeunit在Node.js中编写的模块创build一个testing套件。 该模块是一个基本的音乐播放列表,允许添加和删除曲目的播放列表。 var playlist = function(){ this.__playlist = []; this.__count = 0; }; playlist.prototype = { addtrack:function(track){ if(typeof track !== "object") throw new Error("Track needs to be an oject"); this.__count++; track.id = this.__count; this.__playlist.push(track); return this.__playlist; }, removetrack:function(trackid){ if(typeof trackid !== "number") throw new Error("Pass in a numeric track id"); var trackFound = false; for(var […]

如何使用节点检查器来debuggingnodeunit

我可以: 我可以使用nodeunittestingnode.js模块。 我可以使用节点检查器来debugging我的node.js express站点。 但是如何使用节点检查器来debuggingnodeunittesting? 我尝试了,但没有工作: nodeunit –debug myNodeUnitModule_test.js这不起作用。 我试图安装nodebug 。 并且像这样使用它: nodebug /usr/local/bin/nodeunit myNodeunit_test.js但是在ubuntu( No such file or directory )和mac( env: node\r: No such file or directory ) 几乎工作 节点–debug / usr / local / bin / nodeunit ./routes/edit/bodyTelInfoArraysToObject_test.js 其中/usr/local/bin/nodeunit是由which nodeunit命令获取的path 得到输出: debugger listening on port 5858并在那里执行testing。 但是我不能跳转到debugging:当我打开URL的localhost:8080铬观看debugging: 第一次加载我看到空的文件列表 第二次加载:页面未find。 在我的nodeunittesting中,我写了debugger来停止debugging。 但没有。

Nodeunit命令未find?

我在Windows 7上运行,并使用cygwin安装节点。 我正在跟随如何在mcmahon的nodeunit网站上: http ://caolanmcmahon.com/posts/unit_testing_in_node_js。 我用npm来安装nodeunit,它说它已经安装好了,但是当我去调用它时,nodeunit,它说在所有不同的目录中找不到命令。 我是否必须设置某种pathvariables?