Tag: 摩卡

用mochatestingasynchronous函数

我想testing一个运行在node.js中的asynchronousJavaScript函数,并向http api发出一个简单的请求: const HOST = 'localhost'; const PORT = 80; http = require('http'); var options = { host: HOST, port: PORT, path: '/api/getUser/?userCookieId=26cf7a34c0b91335fbb701f35d118c4c32566bce', method: 'GET' }; doRequest(options, myCallback); function doRequest(options, callback) { var protocol = options.port == 443 ? https : http; var req = protocol.request(options, function(res) { var output = ''; res.setEncoding('utf8'); res.on('data', function(chunk) […]

在WebStorm 11中,Mocha描述了“require()缺失”

我刚刚安装了WebStorm 11,并创build了一个新的项目,但是WebStorm说这个describe方法需要require() : 我已经添加了明确types的摩卡库,范围是testing目录(这个文件是在)。

如果一个失败,跳过后续的摩卡testing

如果其中一个失败,我无法find一个办法来阻止it的一部分运行 我正在使用mocha-as-promised promise,所以代码看起来可能与使用不同 describe("remote promises", function() { describe("browsing", function() { describe("getting page", function() { it("should navigate to test page and check title", function() { this.timeout(TIMEOUT); return browser.get("http://admc.io/wd/test-pages/guinea-pig.html").then(function() { return browser.title(); }).then(function(title) { return assert.ok(~title.indexOf("I am a page title – Sauce Labs"), "Wrong title!"); }); }) it("submit element should be clicked1", function() { this.timeout(TIMEOUT); return browser.elementById("submit").then(function(el) […]

testing在节点中使用mocha / supertestredirect的请求

我似乎无法得到以下的集成testing,通过使用摩卡 , supertest , 应该 (和coffeescript)的快速项目。 考试 should = require('should') request = require('supertest') app = require('../../app') describe 'authentication', -> describe 'POST /sessions', -> describe 'success', (done) -> it 'displays a flash', (done) -> request(app) .post('/sessions') .type('form') .field('user', 'username') .field('password', 'password') .end (err, res) -> res.text.should.include('logged in') done() 相关的应用程序代码 app.post '/sessions', (req, res) -> req.flash 'info', […]

你怎么能用superagent来使用cookies?

我正在用类似这样的快递进行cookie会话pipe理: req.session.authentication = auth; 我用类似的东西来validationauthentication的url if(!req.session.authentication){res.send(401);} 现在我正在用摩卡, superagent和应该build立testing,但是我似乎无法find一种方法来获取/设置与superagent的cookie。 我甚至试图在authenticationtesting之前请求login,但它不工作, 我已经尝试在摩卡BDD套件的before语句中将请求添加到login中,但是它仍然告诉我该请求是未经授权的,我已经testing了从浏览器执行请求的身份validation,但是它不能从套房有什么想法?

Supertest定制节点中的服务器

请温柔一下。 我是新来的asynchronous编码,并已被抛入一个密集的项目,使用节点开发和API服务器。 我很喜欢它,但有些事情不是自然而然的。 我们的项目是使用express js构build的。 我们有一个文件server.js,在这里我们实例化一个express服务器,然后实例化我们的路由器等等。 我需要现在(部分)完整的服务器进行集成testing。 通常我从命令行运行“%node server.js”,然后使用python请求或curl make请求并检查响应。 现在我已经负责编写一个单元和集成testing套件,以便我们可以自动进行testing。 我一直在使用摩卡,现在正在尝试使用超级集成进行集成testing。 问题是supertest需要一个服务器对象,然后它将应用testing,然而我们的文件,build立我们的服务器对象不会返回任何东西。 我不想修改该文件,所以我难以理解如何访问用于testing的服务器对象。 我的服务器文件看起来(部分)如下所示: var express = require('express') var app = express(); // Express Configuration app.use(express.favicon()); //handles favicon request, which keeps it out of the log when using a browser 🙂 app.use(express.bodyParser()); //slurps up the body in chunks the node.js way 🙂 // …and […]

Chrome中的量angular器错误消息“不支持的命令行标志”?

我是Protractor的新用户,我遇到了使用Chrome运行我的testing的错误 ( 错误显示在已启动浏览器的地址栏下面 ): 您正在使用不受支持的命令行标志–ignore-certificate-errors。 稳定性和安全性将受损。 这是我的量angular器conf.js: exports.config = { seleniumAddress: 'http://localhost:4444/wd/hub', capabilities: { 'browserName': 'chrome' }, … 另外,我正在使用最新的可用Chromedriver和Selenium独立服务器(2.41.0)的Mac。 现在,我没有在任何地方设置这个标志,我不记得它总是显示,所以我不知道是什么造成了这个问题。 任何想法如何解决这个问题?

摩卡APItesting:得到'TypeError:app.address不是一个函数'

我的问题 我已经编写了一个非常简单的CRUD API,最近我也开始编写一些使用chai和chai-httptesting,但是在使用$ mocha运行我的testing时遇到了问题。 当我运行testing时,在shell上出现以下错误: TypeError: app.address is not a function 我的代码 这里是我的一个testing( /tests/server-test.js )的示例: var chai = require('chai'); var mongoose = require('mongoose'); var chaiHttp = require('chai-http'); var server = require('../server/app'); // my express app var should = chai.should(); var testUtils = require('./test-utils'); chai.use(chaiHttp); describe('API Tests', function() { before(function() { mongoose.createConnection('mongodb://localhost/bot-test', myOptionsObj); }); beforeEach(function(done) { […]

我如何testing我的快速应用程序与摩卡?

我刚刚添加了shouldjs和mocha到我的快速应用程序进行testing,但我想知道如何testing我的应用程序。 我想这样做: app = require '../app' routes = require '../src/routes' describe 'routes', -> describe '#show_create_user_screen', -> it 'should be a function', -> routes.show_create_user_screen.should.be.a.function it 'should return something cool', -> routes.show_create_user_screen().should.be.an.object 当然,这个testing套件中的最后一个testing只是告诉医生res.render函数(在show_create_user_screen中调用)是未定义的,可能是因为服务器没有运行,configuration尚未完成。 所以我想知道其他人是如何进行testing的?

你如何安装和运行Mocha,Node.jstesting模块? 安装后得到“mocha:command not found”

我很难让Mocha如预期的那样工作,而且我很乐意按照logging来说,但是似乎没有太多关于实际运行的文档。 我已经使用npm (全局和本地)安装它,每当我运行它我得到: $ mocha mocha: command not found 好吧,所以我觉得这不是我的PATH ,所以我试着直接运行它, $ ./node_modules/mocha/bin/mocha execvp(): No such file or directory 最后,我试着打另一个bin文件, $ ./node_modules/mocha/bin/_mocha path.existsSync is deprecated. It is now called `fs.existsSync`. . ✔ 1 tests complete (1ms) 我怎样才能用一个命令执行我的testing? 誓言似乎让你,但我听说摩卡是更好的select,我似乎无法让它正常工作。 对于我在第三次尝试中得到的错误有什么想法? 编辑: 我在跑, Ubuntu 11.10 64位 Node.js 0.7.5 npm 1.1.8 摩卡0.14.1 应该是0.6.0