Tag: 誓言

誓言:testingasynchronous交织

有没有一种方法来testing(潜在的)与asynchronous函数交叉誓言? 例如: // Topic portion var user = new User('jacob') user.set('email,'foo@bar.com') user.save() // a user.set('email',derp@cherp.com') user.save() // b user.refresh(this.callback) // Reload from database // Callback assert.equals(user.email,'derp@cherp.com') 这两个节省之间可能会有一个竞赛条件。 在编写我的testing时,我想确保我的API确保b完成最后(并且我们拥有正确的电子邮件最终值)。 随着写作的方式,testing将在一些巧合的时间通过。

用Vows和Tobi进行Webapptesting

我完全是新的node.jstesting,也许你可以帮助我:我想要做一些或多或less简单的testing我的快速webapp使用誓言和tobi(例如testing如果login路线的作品) var vows = require('vows'); var assert = require('assert'); var tobi = require('tobi'); var browser = tobi.createBrowser(8080, 'localhost'); vows.describe('mytest').addBatch({ 'GET /': { topic: function() { browser.get("/", this.callback); }, 'has the right title': function(res, $) { $('title').should.equal('MyTitle'); } } }).export(module); 我得到这个: ♢ mytest GET / ✗ has the right title » expected { '0': { _ownerDocument: […]

server.close()不能在VOW中拆卸

我正在尝试为我的快速应用程序编写一些基于Vows的testing。 这里是testing来源: var vows = require('vows'); var assert = require('assert'); var startApp = require('./lib/start-app.js'); var suite = vows.describe('tournaments'); suite.addBatch({ "When we setup the app": { topic: function() { return startApp(); }, teardown: function(topic) { if (topic && topic.close) { topic.close(); } }, "it works": function(topic) { assert.isObject(topic); } } }); suite.run(); 这里是start-app.js : var app […]

node.js,testing一个mongodb保存和加载

也许我只是无法找出callbackyness,但我不能找出一种方法来testingnode.js中的保存和加载。 我的testing是这样的: vows.describe('Saving').addBatch({ 'Single item can be saved':{ topic:function () { myStore.saveItems(1, [{id:3,name:'squat'}]); myStore.getItems(1, this.callback); }, 'saved item is returned by getItems':function (err, items) { assert.equal(items.length, 1); assert.equal(items[0].deviceId, 1); assert.equal(items[0].id, 3); } } }).export(module); 有了这个testing: exports.saveItems = function (deviceId, items) { var itemsCollection = db.collection('items'); itemsCollection.find({deviceId:deviceId}).toArray(function (err, existingItems) { _.each(items, function (item) { item['deviceId'] = […]

誓言:命令未find

我从我的应用程序的根文件夹运行我的testing。 testing位于spec目录中。 $ vows No command 'vows' found, did you mean: Command 'vos' from package 'openafs-client' (universe) Command 'voms' from package 'voms-server' (universe) vows: command not found 我的package.json如下 { "author": "Sunil Kumar <sunilkumar.gec56@gmail.com>", "name": "subscription-engine-processor", "description": "Node.js server for Subscription Engine processor application.", "version": "0.0.0", "scripts": { "start": "node index.js" }, "repository": { "type": "git", […]

在testingnode.js应用程序时,什么是存根function的最佳设置?

我是Node.js的新手,并且一般来说还不熟悉JavaScript中的框架/方法。 到目前为止,我正在考虑发誓 。 具体来说,我想能够存根/模拟我的数据源。 我正在考虑两种情况: 将整个模块取出 无论出于何种原因,对整个模块进行存根操作都不起作用。 任何build议或例子,你发现最干净和最简单的方法?

使用誓言的REST APItesting,tobi和node.js

我正在试图结合这里的例子, 在这里写我的node.js / express应用程序的誓言testing: 创build一个新的用户对象 检查响应是否理智 使用返回的_id来testing查找新创build的用户 再次使用_id来testing更新用户 第1项和第2项工作正常,但是我的子上下文“GET / users /:id”有问题。 它的错误,我不明白为什么。 试图谷歌search和使用debugging器,但我仍然不能看到它是什么,我可能只是忽略了一些明显的东西。 ···✗ Errored » 3 honored ∙ 1 errored 谁能告诉我为什么第四个誓言错误? 这是我的誓言代码: var vows = require('vows') , assert = require('assert') , tobi = require('tobi') var suite = vows.describe('Users API') , now = new Date().getTime() , newUser = { name: now + '_test_user', email: […]

Vows.js – 参数数量this.callback返回主题与誓言

从誓言网站:“当这个callback被调用时,它将它收到的参数逐个传递给testing函数,就好像这些值是由主题函数本身返回的。 换句话说,如果我们使用请求库来处理我们的http请求,我们的话题和誓言可能如下所示: 'When I make a valid request': topic: -> request uri: someURL method: "GET" , @callback return undefined # necessary because I'm using coffeescript "It should respond with a 200": (err, resp, body) -> assert.equal resp.statusCode, "200" 但是串联在一起的话题似乎有着不同的规则。 他们似乎只传递一个论点。 以下是Vows网站的一个例子: topic: function () { fs.stat('~/FILE', this.callback); }, 'after a successful `fs.stat`': { topic: function […]

使用Async嵌套主题的誓言 – 范围问题

我希望我的誓言能够访问我的主题中的outerDocs和innerDocs,但事实并非如此。 'ASYNC TOPIC': { topic: function() { aModel.find({}, this.callback); }, 'NESTED ASYNC TOPIC': { topic: function(outerDocs) { anotherModel.find({}, this.callback(null, innerDocs, outerDocs)); }, 'SHOULD HAVE ACCESS TO BOTH SETS OF DOCS': function(err, innerDocs, outerDocs) { console.log(err, innerDocs, outerDocs); return assert.equal(1, 1); } } 我究竟做错了什么?

testing蓝鸟承诺与Nodejs誓言(BDD)

我遇到了一些问题,比如如何正确构build我的Promise返回API的testing topic:function() { return myfunc() { /* returns a Bluebird Promise */ } }, 'this should keep its promise':function(topic) { var myfunc = topic; myfunc() .then(function(result) { assert(false); }) .catch(function(error) { assert(false); }) .done(); } 我的誓言永远不会失败。 这是我第一次尝试使用誓言来testing承诺。 希望有人熟悉这一点会伸出援助之手。 提前,谢谢。 恩里克