Tag: nodeunit

NodeUnit – 使用通配符

我正在使用NodeUnit进行JSON REST API的自动验收testing。 我有一个testing创build资源,它返回创build的资源(根据此规范),我想比较API的结果与我自己的JSON对象,如: test.deepEqual(response.body.data, { type: 'Employees', id: '1', attributes: { Name: 'Marten', Birthdate: '1995/05/25' }, relationships: { Speciality: { links: { self: testBase.baseUrl + 'Employees/1/relationships/Speciality', related: testBase.baseUrl + 'Employees/1/Speciality' } } }, links: { self: testBase.baseUrl + 'Employees/1' } }); 只是一个问题:由于testing(NodeUnit)是asynchronous的,所创build的资源的Id可以是任何东西。 在这种情况下,“1”,但可能是“2”,甚至“95”。 那么,是否有可能使用通配符而不是数字值?

如何设置grunt-contrib-nodeunit来输出JUnit xml?

我找不到任何信息如何在grunt-contrib-nodeunit模块中设置记者,现在我在Gruntfile.js中有这个任务。 nodeunit: { all: ['nodeunit/**/*.test.js'], } 如何告诉grunt使用内置JUnit报告与自定义输出path?

node.js的unit testing

我研究了用node.js开发的一个应用程序编写unit testing的各种框架。 在Mocha中存在多个选项,如:nodeunit,jasmine-node,should.js库。 所有似乎都能testing一切。 我找不到任何上述选项的限制。 我更喜欢使用nodeunit,因为它似乎很容易作为初学者使用。 任何关于nodeunit限制的build议在我开始工作之前都会非常有帮助。 或任何build议,如果有人认为在node.jsunit testing存在一个更容易和更好的select。

使用sinun mocks和nodeunit

我正在学习使用sinun与nodeunit ,特别是做嘲弄。 推荐的方法是使用sinon-nodeunit 。 根据文档 ,mock应该可以通过对每个testing函数的test参数的mock方法来获得。 但是,这似乎并不奏效。 如果我在包含以下内容的文件上运行nodeunit – require('sinon-nodeunit'); exports['test sinon-nodeunit'] = function (test) { mock = test.mock({}); test.done(); }; – 我得到这个: $ nodeunit test/test-sinon-nodeunit.js test-sinon-nodeunit.js ✖ test sinon-nodeunit TypeError: Object #<Object> has no method 'mock' at /home/malkovich/test/test-sinon-nodeunit.js:4:17 at Object.runTest (/usr/local/lib/node/.npm/nodeunit/0.5.1/package/lib/core.js:54:9) at /usr/local/lib/node/.npm/nodeunit/0.5.1/package/lib/core.js:90:21 at /usr/local/lib/node/.npm/nodeunit/0.5.1/package/deps/async.js:508:13 at /usr/local/lib/node/.npm/nodeunit/0.5.1/package/deps/async.js:118:13 at /usr/local/lib/node/.npm/nodeunit/0.5.1/package/deps/async.js:134:9 at /usr/local/lib/node/.npm/nodeunit/0.5.1/package/deps/async.js:507:9 at Object.concatSeries (/usr/local/lib/node/.npm/nodeunit/0.5.1/package/deps/async.js:147:23) […]

Nodeunittesting挂起asynchronous数据库调用ORMnomnom

我正在尝试为asynchronous数据库调用编写unit testing。 我使用ORMnomnom包作为orm数据库访问和nodeunit进行unit testing的NodeJS 。 但是这个简单的testing挂起来了: 这里是代码test \ test1.js modelsdb = require('../model/model_db') exports['test db'] = function (test) { test.expect(1); console.log('test db'); modelsdb.MyTable.objects.all( function (err, data) { test.ok(true, "this assertion should pass"); test.done(); console.log('test must finish here!'); }); } exports.testSomething = function(test){ console.log('testSomething'); test.expect(1); test.ok(true, "this assertion should pass"); test.done(); }; 当我运行这个testing所有的断言通过,我看到我的消息在控制台:'testing数据库''testing必须在这里完成! 'testSomething'(意思是test.done()到达callback函数内部),但是testing没有完成。 我需要手动停止它,得到:'处理完成退出代码1'。 如果我更改为test.ok(false,“”),所以我得到AssertionError但testing没有完成。 如果我删除“testing数据库”,只留下testSomething函数 […]

如何断言nodeunit中的错误消息?

我试图编写断言,检查nodeunit中的错误消息。 如果错误信息与我期望的不符,我想testing失败。 但是,它似乎不存在这样的API。 这是我正在做的事情: foo.js function foo() { … throw new MyError('Some complex message'); } foo.test.js testFoo(test) { test.throws(foo, MyError, 'Some complex message'); } 如果错误消息不是 “一些复杂的消息”,我想要testFoo失败,但这不是它的工作原理。 看起来像“一些复杂的信息”只是一个解释testing失败的信息。 它不涉及这个断言。 什么是最好的方式来做到这一点在nodeunit?

NodeUnit启用和声function

我是新的nodejs,我不知道如何可以启用和谐function在nodeunit? 我知道我可以使用nodeunit标志在node启用它们,但nodeunit没有这个标志。 我正在寻找let工作。

可能告诉nodeunit在调用test.done()之前不要完成特定的testing?

我正在做一些与nodeunit的asynchronoustesting,我想知道是否有可能告诉nodeunit在test.done被调用之前不终止testing用例。 基本上这是我的testing用例现在的样子: exports.basic = testCase({ setUp: function (callback) { this.ws = new WrappedServer(); this.ws.run(PORT); callback(); }, tearDown: function (callback) { callback(); }, testFoo: function(test) { var socket = ioClient.connect(URL); socket.emit('PING', 1, 1); socket.on('PONG', function() { // do some assertion of course test.done(); }); } }); 现在的问题是,PONG不能够快速地被发送回来,以便testing代码被执行。 有任何想法吗?

当testing失败时,TravisCI并没有失败

我有用 JavaScript编写的testing,我使用TravisCI进行testing。 build立 我的package.json是这样的: "scripts": { "test": "node testsRunner.js" } 而我的.travis.yml是: language: node_js node_js: – '0.12.7' 'testsRunner.js'是: var nodeunit = require('nodeunit'); var path = require('path'); nodeunit.reporters.default.run([ path.join(__dirname, 'suite1/test.js') ]); 而suite1/test.js最后是: module.exports = { setUp: function(callback) { // Initialization code… callback(); }, tearDown: function(callback) { // Cleanup… callback(); }, test1: function(test) { test.expect(10); // This test […]

如何在Nodeunit中添加自定义断言

有没有办法将自定义断言添加到传递给每个testing的NodeUnit test对象? 我想要做一些事情: var Test = require('nodeunit').Test; Test.prototype.customAssertion = function(obj) { test.same(obj.foo, 'bar'); test.same(obj.bar, 'baz'); } exports.test = function(test) { test.customAssertion(obj); test.done(); }