Tag: 誓言

重用节点中的MongoDB连接

这是我得到的错误: [Error: db object already connecting, open cannot be called multiple times] 。 我在这个誓言testing中有一个全球性的mongo对象。 mongo = new mongo.Db(config.api.apiTest, new mongo.Server('localhost', 27017, {}), {native_parser: off, safe: true}) 当我第二次尝试打开它时出现此错误。 所以即使我第一次使用db.close()它似乎并不closures。 有没有其他方式重新使用连接? .addBatch( "Redis – ": "Standard account – ": topic: -> # . redisClient.del "#{ accountId }:900" mongo.open (error, db) => secondDb = db.db config.api.accountTest secondDb.collection 'accounts', […]

在Vows.js中,如何在经历asynchronouscallback之后恢复原始主题?

说我有以下顺序: vows.describe('Example').addBatch({ 'An example' : { topic: new Example(), 'with an async method' : function(example) { example.asyncMethod(this.callback); }, 'will do some magic' : function(err, result) { assert.equal(result.magical, true); }, 'and then we will be back on track' : function(example) { assert.isTrue(example.backOnTrack); } } }).run(); 是testing“ and then we will be back on track ”可能击中前面的话题( Example […]

在誓言中,是否有`beforeEach“`设置function?

誓言有一个无证的teardownfunction,但我不能看到任何方式来setup每个testing之前(又名beforeEach )的东西。 人们会认为有可能作弊和使用这个topic ,但一个话题只能运行一次(如teardown ),而我希望在每次testing之前运行这个话题。 这不能在誓言中完成吗?

使用Zombie.js查询Backbone.js应用程序的DOM

只是今天第一次尝试了Zombie.js ,而且我无法访问通过javascript(特别是Backbone.js应用程序)填充DOM元素的页面。 作为一个简单的例子,我访问了Backbone.js Todo应用程序并手动添加了一些项目。 然后,我试着用僵尸来抓取#todo-list元素中的html,然后空着。 我已经设置browser.runScripts = true ,所以不应该一切准备僵尸查询? 查看源代码,内部HTML确实是空的。 这甚至有可能与Zombie.js? 还是我需要使用像茉莉花这样的东西呢? 我已经包括下面的示例代码,以及我得到的回应。 var zombie = require('zombie'), vows = require('vows'), assert = require('assert'); var baseUrl = 'http://documentcloud.github.com/backbone/examples/todos/index.html'; vows.describe('Zombie Tests on a Backbone App').addBatch({ 'Navigate to Todo List' : { topic: function () { browser = new zombie.Browser({ debug: true }); browser.runScripts = true; browser.on('error',function (err){console.log(err.stack)}); […]

如何用Vows和Node.js解决“callback没有被解雇”

我正在尝试开始誓言和誓言BDD 。 不幸的是,callback让我沮丧。 在下面这个非常简单的例子中,如何解决这个错误? ** Inside the first context ** Creating Person with name Nick ✗ Errored » callback not fired in Create a Person via JavaScript: When a person has a name, in Creating a Person in undefined✗ Errored » 1 errored 1 dropped vows_bdd = require "vows-bdd" assert = require "assert" class Person […]

这是在Node中做dependency injection的正确方法吗?

我最近启动了一个节点项目,作为一名testing驱动开发人员,我用我的全新模块很快遇到了dependency injection问题。 以下是我如何计算出我应该做dependency injection。 注意我使用誓言作为BDD框架并且用Sinon扩展它是重要的。 我的模块: exports.myMethod = function () { var crypto = exports.cryptoLib || require('ezcrypto').Crypto; crypto.HMAC( crypto.SHA256, 'I want to encrypt this', 'with this very tasty salt' ); }; 我的testing: var vows = require('vows'), sinon = require('sinon'); vows.describe('myObject').addBatch({ 'myMethod':{ 'topic':true, 'calls ezcrypto.HMAC':function () { var myObject = require('../playground.js'); var mock = sinon.mock(require('ezcrypto').Crypto); myObject.cryptoLib […]

testingMongooseJsvalidation

有谁知道如何testingmongoosevalidation? 例如,我有下面的Schema(作为例子): var UserAccount = new Schema({ user_name : { type: String, required: true, lowercase: true, trim: true, index: { unique: true }, validate: [ validateEmail, "Email is not a valid email."] }, password : { type: String, required: true }, date_created : { type: Date, required: true, default: Date.now } }); validateEmail方法定义如下: // Email […]

Node.jstestingRESTful API(vows.js?)

我真的可以做一些关于testing我在node.js中创build的RESTful api的build议。 那里有很多框架,我不知所措。 我的testing知识一般不够好,这就是为什么我要写这些testing。 我已经尝试了vows.js这似乎很好,但我无法工作如何纳入我的API的testing,我需要某种客户端。 一个简单的post来testinglogin系统的例子是我需要去的。

如何运行与vows.js清理?

我使用Vows.js来testing一些在数据库中创buildlogging的node.js。 这样做会在数据库中创build一些testinglogging。 一旦testing运行,我想删除这些logging。 有一种方法可以在Vows中运行一批testing时运行清理函数吗?

带有require的node.js中的命名空间

我正在玩一个个人项目并且学习发誓。 这是一个小型的客户端库,testing在誓言中完成。 因此,我必须build立和testing这样写的文件: (function(exports) { var module = export.module = { "version":"0.0.1" }; //more stuff })(this); 在我的testing中(基于science.js ,d3等)需要这样的模块: require("../module"); 当我试图运行testing时,我继续得到一个“模块未定义的错误”,所以我去了一个repl,跑了: require("../module") 并返回: { module: { version: "0.0.1" } } 我意识到我可以做这样的事情: var module = require("../module").module; 但感觉就像我正在用这种方式创build一个问题,特别是因为我基于这个项目的库以我描述的格式进行。 我希望我的项目的行为类似于我以此为基础的项目,其中: require("../module"); 在这个命名空间中创build一个variables: module.version; //is valid. 我已经在各种图书馆看到了这一点,我正在遵循T的格式和思维过程,但相信我可能会错过某些我不知道的需求行为。