Tag: mocha

Zombie.js“断言没有定义”多次访问?

我正在与Zombie.js和Mocha进行集成testing,并遇到了令人困惑的问题,即只有第一个browser.visit()调用似乎成功了。 我的规格是这样的: browser = new Browser site: "http://localhost:101010" describe '/docs', -> ['app', 'server', 'timetable', 'util'].forEach (file) -> describe "/#{file}.html", -> it "documents #{file}.coffee", (done) -> browser.visit "/docs/#{file}.html", -> browser.text('title').should.equal "#{file}.coffee" do done 其中的第一个加载/docs/app.htmltesting没有发生。 但是,所有后续testing都会失败,产生如下的堆栈跟踪: ReferenceError: assert is not defined at Object.HTML5Parser.phases.inBody.startTagBody (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/parser.js:1828:4) at Object.HTML5Parser.phases.base.processStartTag (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/parser.js:65:40) at EventEmitter.Parser.do_token (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/parser.js:2436:21) at EventEmitter.<anonymous> (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/parser.js:2457:30) at EventEmitter.emit (events.js:117:20) at […]

Should.js在一个属性上链接多个断言

我有这样一个对象: var obj = { "uuid": "60afc3fa-920d-11e5-bd17-b9db323e7d51", "type": "candy" } 我想写一个testing,首先检查对象的属性“uuid”,然后“uuid”是一个特定的长度(36个字符)。 试试这个不行 obj.should.have.property('uuid').which.should.have.length(36) 它失败: Uncaught AssertionError: expected Assertion { obj: '60afc3fa-920d-11e5-bd17-b9db323e7d51', params: { operator: 'to have property \'uuid\'' }, negate: false } to have property 'length' of 36 (got [Function]) 而这(实际上不会使语法意义 – 因为它将适用于父对象而不是值) obj.should.have.property('uuid').and.be.length(36) 哪个失败: Uncaught TypeError: usergridResponse.entity.should.have.property(…).which.should.be.equal.to is not a function 即使这不起作用: obj.should.have.property('uuid').which.equals('60afc3fa-920d-11e5-bd17-b9db323e7d51') 那么链接对象属性的断言的正确方法是什么?

testingGraphQL API

我正在testing我的GraphQL API,但我想稍微清理一下。 值得注意的是,我正在使用chai-http作为networking请求。 这是我目前正在做的(哪些工作): let createUser = (()=> { return new Promise((resolve, reject) => { chai.request(server) .post('/api/graphql/') .set('content-type', 'application/json') .send({ 'query' : 'mutation users { \ user : addUser(inputs: { \ firstName: \"Test\", \ lastName: \"User\", \ email: \"test@test.com\", \ }) { \ id, \ firstName \ } \ }' }) .end((err, res) => { […]

摩卡芒果错误

mongoose试图连接到mongodb时,在我的摩卡testing中出现以下错误: Error: Trying to open unclosed connection. 这是我的testing: var cfg = require('../config') , mongoose = require('mongoose') , db = mongoose.connect(cfg.mongo.uri, cfg.mongo.db) , User = require('../models/user') , Item = require('../models/item') , should = require('should') , fakeUser , fakeItem; mongoose.connection.on('error', function(err){ console.log(err); }); describe('User', function(){ beforeEach(function(done){ //clear out db User.remove(done); }); after(function(done){ //clear out db User.remove(function(err){ Item.remove(done); […]

无法连接到socket.io两次

我写了一个socket.io服务器,我用mocha来testing它。 但是我无法第二次连接到服务器。 这是我的代码,它是由咖啡脚本写的。 服务器: server = require('http').Server() io = require('socket.io').listen(server) io.on 'connection', (socket) -> console.log socket.id server.listen(3000) testing: chai = require 'chai' io = require 'socket.io-client' should = chai.should() describe 'Socket', ()-> url = 'http://0.0.0.0:3000' it 'should be connected', (done) -> client = io.connect(url) client.on 'connect', (data) -> console.log(data) client.socket.connected.should.equal(true) client.disconnect() done() describe 'User', ()-> […]

摩卡没有运行testing目录中的所有testing

这是我的文件夹结构 src/ a.js b.js test/ a.spec.js b.spec.js 我试过跑步 ~/…/src $ mocha ~/…/src $ mocha test ~/…/src $ mocha test/ ~/…/src $ mocha ./test/ ~/…/src $ mocha ./test/*.js 但没有工作…我得到的只是一个testing文件运行,其余的被忽略。 文件说,(1)应该做的工作,但没有。

调用路线进行摩卡testing

我正在尝试使用摩卡和柴编写unit testing,我面临的主要问题是,对于每个API我必须明确定义的url,即 test.js var expect = require('chai').expect; var should = require('chai').should; var express = require('express'); var chai = require('chai'); var chaiHttp = require('chai-http'); chai.use(chaiHttp); var baseUrl = 'http://localhost:3000/api'; describe("Test case for getting all the users", function(){ it("Running test", function(done){ this.timeout(10000); //to check if the API is taking too much time to return the response. var […]

是否有可能在testing中设置amdefine,以便我不必在所有模块文件中定义它?

我有一套使用浏览器端,但testing服务器端与摩卡的对象。 我使用require.js进行AMD加载。 Require.js网站build议在服务器端使用amdefine来获取定义的模块在node.js中的这一点代码: if (typeof define !== 'function') { var define = require('amdefine')(module) } 好。 但是我必须把它放到我想在Node中使用的每个模块中。 在我的情况下,这意味着我不得不从我使用客户端(大部分)的任何代码中删除它。 我想知道是否有任何方法把我的testing中的代码块,所以我不必把它放在我的客户端代码。 在我的文件中只有testing需要的代码似乎很愚蠢 – 把它放在testing代码中更有意义。 但是,当我这样做,我得到一个错误: Error: amdefine with no module ID cannot be called more than once per file. at runFactory (/home/vmplanet/dev/alpha/web/node_modules/amdefine/amdefine.js:159:23) at define (/home/vmplanet/dev/alpha/web/node_modules/amdefine/amdefine.js:275:13) at Object.<anonymous> (/home/vmplanet/dev/alpha/web/assets/src/coffee/delta/dataLayer.coffee:4:3) at Object.<anonymous> (/home/vmplanet/dev/alpha/web/assets/src/coffee/delta/dataLayer.coffee:158:4) at Module._compile (module.js:456:26) at Object.loadFile (/usr/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:179:19) at […]

zombie.js和Google Maps API

我遇到了zombie.jstesting框架和Google Maps API的问题。 我有一个简单的zombie.js加载主页,并尝试点击login链接。 但是,当我查看返回的主页HTML(从zombie.js浏览器对象的angular度来看),我只在主体部分看到这一点: <body> <script src="https://maps.gstatic.com/intl/en_us/mapfiles/api-3/9/12/main.js" type="text/javascript"></script> </body> 如果我从原始页面中删除Google Maps JavaScript,那么一切正常,我将得到完整的部分。 请求不使用地图API的不同页面也可以正常工作。 我在这里看到一个相关的问题,但解决方法没有完全描述: https : //github.com/assaf/zombie/issues/250 任何人都可以帮助我完全解决这个问题吗? 这里是有问题的zombie.js代码: suite('Zombie Sign In', function() { test('Home page should have sign-in link', function(done) { var browser = new Browser(); browser.debug = true; browser.authenticate().basic(conf.basicAuth.username, conf.basicAuth.password); browser.visit(conf.baseURL, function(e, browser) { console.log(browser.html()); // here is where I get the […]

Node.js + Chai / Mocha /应该:针对相同的响应运行多个testing

我正在使用与以下类似的东西来执行一系列使用Mocha的APItesting。 这很好,但是它需要为每个testing制作一个单独的API调用。 我想要使​​用相同的API调用,并针对该响应运行多个testing。 我一直在阅读你before可以使用的方法,但是Web上的所有例子都没有显示它使用API​​调用? var chai = require('chai'); var request = require('request'); var async = require('async'); var assert = chai.assert, expect = chai.expect, should = chai.should(); describe('/', function () { it('should return 200', function (done) { request.get('http://localhost:8000', function (err, res, body) { res.should.have.status(200); done(); }); }); it('should say "Hello, world!"', function (done) { request.get('http://localhost:8000', function […]