Tag: 摩卡

用摩卡testingFacebook应用程序

我正在开发一个使用Facebooklogin的node.js应用程序,我正在尝试使用mocha进行单元和集成testing。 所以在一个函数,我有这个代码为了login: exports.loginFacebook = function (done){ request({uri:"https://graph.facebook.com//oauth/access_token?client_id={app-id}&client_secret={app-secret}&grant_type=client_credentials", method: "GET", timeout: reqOpts.timeout}, function(err, res, body) { if(err){ throw err; } else{ uri2 = "https://graph.facebook.com/APP_ID/accounts/test-users?"+String(body); request({uri:uri2, method: "GET", timeout: reqOpts.timeout}, function(err, res, body) { if(err){ throw err; } else{ login_url = JSON.parse(body).data[0].login_url console.log(login_url); request({uri:login_url, method: "GET", timeout: reqOpts.timeout}, function(err, res, body) { if(err){ throw err; } else{ […]

testing摩卡预期的超时时间

我有一个Faye发布/订阅服务器,只有当消息已经发送给其他订阅者时,才向新订阅者发送消息。 我正在使用摩卡进行unit testing。 这个testing的目的是确认基本function: it('should send a special message to new subscribers', function(done){ testerPubSub.setLastJsonContent('some arbitrary content'); var subscription = client.subscribe("/info", function(message) { assert.equal(true, message.text.indexOf('some arbitrary content') !== -1, 'new subscriber message not sent'); done(); }); subscription.cancel(); }); 但是现在我想testing一下没有消息发送给以前的用户的情况。 这个testing会是这样的: it('should not send a special message to new subscribers if no data has been retrieved', function(done){ […]

摩卡testingi18n TypeError:无法读取未定义的属性'text50'

我正在使用摩卡testing框架来testing我的应用程序和翻译我使用从mashpie i18n。 在我的validation.js文件中,我需要i18​​n模块并使用i18n .__函数 console.log(i18n.__('text50')); 在我的testing文件validation.test.js我需要validation.js进行testing。 然后我用摩卡运行testing,因为我得到的结果。 Running "mochaTest:test" (mochaTest) task >> Mocha exploded! >> TypeError: Cannot read property 'text50' of undefined >> at translate (/Volumes/Develop/townspeech/node_modules/i18n/i18n.js:355:23) >> at Object.i18nTranslate [as __] (/Volumes/Develop/townspeech/node_modules/i18n/i18n.js:96:11) >> at Object.<anonymous> (/Volumes/Develop/townspeech/server/libs/validation.js:24:18) >> at Module._compile (module.js:456:26) >> at Object.Module._extensions..js (module.js:474:10) >> at Module.load (module.js:356:32) >> at Function.Module._load (module.js:312:12) >> at Module.require […]

摩卡unit testing节点模块,模块variables奇怪

生病了一些代码的业务: hangman.io.js: var from = require('fromjs'), fs = require('fs'); var defaultBasePath = 'lib/hangman/wordlists'; var filePaths = []; function init(basePath) { basePath = basePath || defaultBasePath; filePaths = loadPaths(basePath); } function loadPaths(basePath) { var wordLists = fs.readdirSync(basePath); return from(wordLists).select(function (x) { return basePath + '/' + x; }).toArray(); } function getFilePath(type) { if (!filePaths || !(filePaths […]

节点快速应用程序 – 构造单元/集成testing

我试图为我的nodejs / express应用程序设置我的testing套件。 我有一个类似于这个例子的结构,我有一个应用程序文件夹,其中是模型,视图,控制器文件夹。 我有我的testing目录目前拆分为 单元 积分 在单元里面,我模仿了app的文件夹结构。 我有我的模式等unit testing…保存到一个testingMongoDB实例 我的问题是,我应该unit testing我的控制器,还是应该保存集成testing? 我的“控制器”看起来像: 控制器/ account.js exports.login = function(req, res) { res.render('account/login', { title: 'Log In' }); }; exports.login_post = function(req, res, next) { passport.authenticate('local', function(err, user, info) { if (err) { return next(err); } if (!user) { return res.redirect('/account/login'); } req.logIn(user, function(err) { if (err) […]

从testing中解耦查询的最佳实践

我正在寻找使用mocha或sinontestingmysql查询的最佳实践。 我试图testing非常基本的数据库查询,如保存: User.prototype.save = function(cb) { var query = 'INSERT INTO user (name, email, password, img, description)' + 'values (?, ?, ?, ?, ?)'; var params = [this.name, this.email, this.pass, this.img, this.description]; db.query(query, params, function(err, rows) { if (err) return cb(err); cb(rows.insertId); } ); }; 我相信我想做一个模拟数据库,并使用该对象,而不是我的数据库对象,但我也想分开testing逻辑从应用程序逻辑。 我尝试了一些变化 describe('User', function() { before(function() { mock = sinon.mock(require('../middleware/db')); […]

如何在NodeJs中loggingwebdrivertesting的video

我打算使用node.JS webdriver / Mocha /量angular器中的任一个。 有没有一种简单的方法来录制video中的任何一个? 我已经看过在运行testing时使用ffmpeglogging整个屏幕的选项,但是如果有任何nodejs库可以帮助我直接logging任何这些video。 我会用这个。

Mocha作为Nodejs中的库

我们有我们所有的用摩洛哥语言编写的用户界面testing。 如果可以使用摩卡作为库并从expressjs运行这些testing,这将是非常方便的。 我已经在网上search,只有参考我能find的是摩卡作为超过2岁的图书馆 。 此外,答案中给出的链接被打破。 我想运行我的testing的方式是,当我打电话时,它应该运行testing,并在db中更新状态。 我觉得能够使用摩卡作为图书馆将是我的用例更干净的方法。 我可以用命令行来testing他的testing $ $EDITOR test/test.js var assert = require("assert") describe('Array', function(){ describe('#indexOf()', function(){ it('should return -1 when the value is not present', function(){ assert.equal(-1, [1,2,3].indexOf(5)); assert.equal(-1, [1,2,3].indexOf(0)); }) }) }) $ mocha . ✔ 1 test complete (1ms)

摩卡:如何添加代码块(testing为函数/string),而不是mocha.addFile

我以编程方式使用Mocha,并在有关如何添加testing文件的链接中详细介绍了这些内容,但是我已经将以db为单位的testing保存为string。 有没有一种方法,我可以直接将它们添加为string/函数,而不是创build临时缓冲区,并将它们添加为文件? //write my tests stored as strings into filesystem fs.writeFile("tempdir", myTest, function(err) { if(err) { return; } }); var mocha = new Mocha; // Then, you need to use the method "addFile" on the mocha // object for each file. // Here is an example: fs.readdirSync('tempdir').filter(function(file){ // Only keep the .js files return file.substr(-3) […]

如何在运行摩卡testing之前等待一个咕噜的任务完成

简而言之… 我有一些我想要testing的外部configuration的咕噜任务(确保他们做他们应该做的)。 所以我想写一个摩卡testing在before函数中运行任务,并声明一切顺利。 …和一些细节 在我的gruntfile有类似的东西 # Load task configs from `grunt` dir. configs = require('load-grunt-configs') grunt, config: src: ['tasks/*{.js,.json,.coffee,.cson}'] # Load all **grunt tasks** with patter `grunt-*` require('load-grunt-tasks') grunt, pattern: [ 'grunt-*' ] # Pass configs to grunt grunt.initConfig configs 并随后进行一些任务注册… 然而,我现在可以访问我的less任务驻留在我的tasks文件夹(使用grunt-contrib-less ) less.cson 。 到现在为止还挺好。 🙂 我使用chai来断言: describe('Checking static resources for dev', function () […]