Tag: jasmine node

为什么茉莉节点mongoose检测不等,像预期的那样?

我正在写一个简单的应用程序,保存和查找位置。 我正在使用mongoose和茉莉节点。 用户CRUDtesting按预期工作。 但是,我个人创build了用户来testing不同的自定义validation。 我也通过清除收集和重新加载所有用户来开始testing,以确保在启动save / update / etctesting之前,所有testing数据都是好的。 对于位置,我做的是一样的,但我有几十个位置,我想用数组加载它们…并testing负载沿途,以确保它工作正常。 如果我只做一个位置,它工作正常。 不止一个,他们失败了。 我知道我错过了一些asynchronous相关的步骤在这里,但我要么search错误的条款,要么我现在太接近它看到我在这里做的根本简单的错误。 版本: mongoose:3.6.16 茉莉花节点:1.11.0 mongodb:2.4.5 细节testing… it("creating location succeeds", function(done){ for(var locIndex in testLocations) { locations.create(testLocations[locIndex], function(err, location){ // console.log says location is undefined // unless there is only one location, then it works. expect(err ).toBeNull(); expect(location.name ).toBe(testLocations[locIndex].name); done(); }); } }); …和创buildfunction从一个单独的文件举行位置相关的function… […]

如何覆盖函数的构造函数属性

我是JavaScript编程新手,我甚至不知道如何去问Google,所以我会详细描述我想实现的目标。 我使用node.js和xml2js模块为茉莉花创buildDataProvider类,parsing简单的XML文件: <Tests> <Test name="test1"> <values>2,4,6</values> <expectations>1,2,3</expectations> </Test> <Test name="test2"> <values>8,10,12</values> <expectations>4,5,6</expectations> </Test> </Tests> 我想要DataProvider构造函数立即parsingXML,并在this.testData显示结果。 脚本是: var fs = require('fs'), xml2js = require('xml2js'), util = require('util'); var DataProvider = function(dataPath) { this.dataPath = dataPath; this.testData; fs.readFile(this.dataPath, function(err, data) { var parser = new xml2js.Parser(); parser.parseString(data, function(err, result) { //console.log(util.inspect(result, false, null)); this.testData = result; }); […]

使用Jasmine-Node进行testing时,Mongoose模型自定义函数中消失的值

我试图在我的Mongoose模型上testing我的自定义方法,但是我在testing模型中设置的值消失,并使testing失败。 testing看起来像这样: it('should get the friend id', function(){ var conversation = new Conversation({ 'users': [new ObjectId('0'), new ObjectId('1')] }); expect(conversation.getFriendId('0')).toEqual(new ObjectId('1')); }); 我的模型声明包含这个: var mongoose = require('mongoose'); var ObjectId = mongoose.Schema.Types.ObjectId; var ConversationSchema = new mongoose.Schema({ 'users': [{'type': ObjectId, 'ref': 'User'}] }); ConversationSchema.methods.getFriendId = function(userId) { return this.users; //return this.users[0] === new ObjectId(userId) // ? […]

frisbyjstesting失败,因为get()没有发送HTTP头

我有另一个frisbyjstesting的afterJSON()失败后frisbyjstesting。 当我debugging服务器代码时,看起来x-access-token和x-key HTTP头没有被发送。 我发错了吗? 当然,我正在做一些愚蠢的事情。 以下是外部testing。 afterJSON()中的第一个testing是失败的: frisby.create('Should be able to log in with test user') .post(appHost + '/login', { username:'test@voxoid.com', password:'pass123' }, {json: true}, {headers: {'Content-Type': 'application/json'}}) .expectStatus(200) .expectJSONTypes({ token: String }) .expectJSON({ user: { name:'test', role:'admin', username:'test@voxoid.com' } }) .afterJSON(function(res) { // TODO: The functionality works, but this test does not; the headers […]

如何从Jasmine获得更好的terminal输出?

当我运行我的testing时,我在terminal输出中得到的是红色和绿色的点,我想看看所有规格的清单,以及他们是否通过或失败类似于摩卡和柴。 任何想法如何从茉莉花得到这个期望的输出?

node.jsunit testing模拟依赖

我有一个关于使用proxyquire(或任何其他build议如何testing下面的代码) 如果我有以下文件来testing: var path = require('path'); module.exports = function (conf) { var exported = {}; exported.getIssue = function (issueId, done) { … … }; return exported; }; 如何在使用proxyquire模拟path时传递'conf'variables; VAR? 有没有其他的方式来做到这一点,如果不使用proxyquire?

茉莉花testing用例不从mongo保存返回

我使用https://github.com/mhevery/jasmine-node来testing我的nodejs服务器路由。 我的mongoose模型有一个工作前置function如下 userSchema.pre('save', function(next) { var user = this; if (!user.isModified('password')) return next(); bcrypt.genSalt(10, function(err, salt) { if (err) return next(err); logger.info('Hashing password!!!'); bcrypt.hash(user.password, salt, null, function(err, hash) { if (err) return next(err); user.password = hash; next(); }); }); }); 现在我需要在jasmine中编写一个testing用例,创build一个userSchema对象并将其保存到mongodb中,以便在testing用例中进一步使用它。 var User = require("../../../../models/User"); it("{postLogin – invalid}", function(done) { var user = new User({email: […]

如何扩展更多的“期望”functionfrisby.js?

有没有办法用自定义expect方法来扩展Frisby.js模块? 我不想修改源代码,这些扩展特定于我的REST API。 我的目标是通过将它们组合成一种方法来避免重复常见的testing。 问题是Frisby.js模块用这个代码导出它的方法: exports.create = function(msg) { return new Frisby(msg); }; 我如何将新方法添加到Frisby? 这更像是一个Javascriptinheritance问题,因为它适用于Node.js模块。 例如,testing.expect API的脚本会有很多重复的.expect子句,如.expectHeader()和.expectJSONTypes() 。 我想将这些结合到一个.expectSEwrapper()方法中。 此方法对于StackExchange API是唯一的,因此它不属于Frisby.js。 该脚本将如下所示: var frisby = require('frisby'); frisby.create('StackOverflow Info') .get('https://api.stackexchange.com/2.2/info?site=stackoverflow', {gzip: true}) .expectStatus(200) .expectHeader('content-type', 'application/json; charset=utf-8') .expectHeader('content-encoding', 'gzip') .expectJSONTypes('', { items: Array, has_more: Boolean, quota_max: Number, quota_remaining: Number }) .toss(); frisby.create('StackOverflow Badges') .get('https://api.stackexchange.com/2.2/badges?order=desc&sort=rank&site=stackoverflow', {gzip: true}) .expectStatus(200) […]

testing需要nodejs中的茉莉花模块

我可以加载需要在节点模块来testing茉莉花。 她的我的规格亚军 var coffee, isVerbose, jasmine, key, showColors, sys, i, len, jasmine = require('jasmine-node'), fs = require("fs"), sys = require('sys'); for (i = 0, len = jasmine.length; i < len; i++) { key = jasmine[i]; global[key] = jasmine[key]; } isVerbose = true; showColors = true; coffee = true; process.argv.forEach(function(arg) { switch (arg) { case '–color': […]

使用frisby.js或jasmine-nodetesting证书到期

我试图写一个testing用frisby.js检查证书的状态。 在证书过期n天之前,testing应该失败,n在下面定义: config.numberOfDaysBeforeTestFails 我用这个代码试了一下: var frisby = require('frisby'); var config = require('../config'); //load own config-file var request = require('request'); frisby.create('https2.0 – Perperation') .get(config.server + '/testData') .auth(config.username, config.passwort) .after(function(err, res, body){ var auth = "Basic " + new Buffer(config.username + ":" + config.passwort).toString("base64"); var r = request({ url: '<serverURL>', requestCert: true, rejectUnauthorized: false, headers : { […]