Tag: chai

在Travis的后台运行节点服务器

我试图对travis进行unit testing,它需要一个位于单独目录中的节点服务器来运行。 所以我需要在运行chai-mochatesting之前让服务器在后台运行。 但是我一直有很多麻烦得到这一切工作…这里是我的.yml文件 language: node_js node_js: – "6.10.0" services: mongodb env: – TEST_DIR=UserService/server – TEST_DIR=ApplicantService – TEST_DIR=ta-corrd-service before_script: – sleep 15 script: – cd UserService/server && npm install nodemon && npm install && npm start& cd $TEST_DIR && npm install && npm test 我需要进入userservice / server目录,然后执行npm start,然后在每个test_dir中执行npmtesting。 错误我得到特拉维斯 > proj-awol@0.0.0 test /home/travis/build/csc302-2017-spring/proj-Awol/ta-corrd-service > mocha […]

NodeJs,moch / chai在macOS上出现“Segmentation fault:11”失败

我正在运行mocha / chai(3.2.0 / 3.5.0)基于我的nodejs(6.10.2)基于应用程序的testing用例,在macOS 10.12.4,我运行到“分段错误:11”失败。 到目前为止我已经尝试过: 擦除我的node_modules文件夹并做一个新的npm install 检查过时的依赖关系并升级它们 通过sudo port upgrade nodejs6升级nodejs版本(使用6.7.0) 对我来说失败的代码如下。 chai.request(url) .post(`/api/filestore?token=${token}`) .timeout(20000) .attach('file', fs.readFileSync(filepath), filename) .field('name', data.name) .field('description', data.description) .field('keywords', data.keywords) .end(function(err, res) { if (err) { done(err); } res.should.have.status(200); res.should.be.json; res.body.should.have.property('name'); res.body.should.have.property('description'); res.body.should.have.property('categories'); res.body.keywords.should.be.a('array'); res.body.keywords.join(',').should.be.equal(data.keywords); done(); }); 删除“附加”行时,分段错误消失: .attach('file', fs.readFileSync(filepath), filename) 我已经单独尝试了fs.readFileSync(filepath) ,我没有遇到这个问题。 这在过去不是问题,最近才成为问题。 我想知道它是否与操作系统的升级是一致的,但我不能确定。 testing文件只有34K大小。 有没有人有什么build议? 编辑:在Ubuntutesting机上也出现分段错误。

其他响应代码,然后200在柴

林新来柴。 据我所知,为了使testing工作,路线应该总是返回http代码200.是正确的? 只要我有一个路线返回其他然后200我在testing套件中出现错误(例如未捕获的错误:内部服务器错误)。 在我的路线,当传递的数据是错误的(例如validation)我想返回其他代码超过200.我想我读了一个地方,可能是好的做法是返回其他代码比200不是返回OK的资源例如vaidation错误或数据库错误)。 但是,似乎我又要回200个柴油testing工作。 我是否错过了一些东西呢?

为什么这些柴testing不会失败?

我们有一个简单的“这是真正的工作”使用Spectron和WebdriverIO一个电子应用程序的柴testing。 我们开始的示例代码是从 https://github.com/jwood803/ElectronSpectronDemo报告在https://github.com/jwood803/ElectronSpectronDemo/issues/2中 ,chai-as-promisedtesting不捕获不匹配,所以我想我会添加一些额外的testing,以找出为什么柴是不是失败的testing电子应用程序的文本不符合预期的unit testing文本。 让我们从简单的东西开始,其余的代码在https://github.com/drjasonharrison/ElectronSpectronDemo describe('Test Example', function () { beforeEach(function (done) { app.start().then(function() { done(); } ); }); afterEach(function (done) { app.stop().then(function() { done(); }); }); it('yes == no should fail', function () { chai.expect("yes").to.equal("no"); }); it('yes == yes should succeed', function () { chai.expect("yes").to.equal("yes"); }); 第一次unit testing失败,第二次成功。 而当我们把这个断言放到一个函数中时,它仍能检测到这个失败: it('should fail, but succeeds!?', […]

AssertionError:expected {Object(__flags)}有属性'_id'

我用摩卡和柴testing我的代码。 我的代码如下所示: let mongoose = require("mongoose"); let Item = require('./../model/items.js'); let chai = require('chai'); let chaiHttp = require('chai-http'); let server = require('../app.js'); let should = chai.should(); chai.use(chaiHttp); describe('Items', () => { beforeEach((done) => { Item.remove({}, (err) => { done(); }); }); describe('/GET item', () => { it('it should GET perticular item', (done) => { chai.request("http://localhost:3000") […]

chai http附加设置内容typesmultipart-formdata

我想将文件作为二进制传递给我想使用chai http编写testing的函数之一,下面是代码: chai.request('http://localhost:8085') .post('/myAPI/' + req.params.id + '/logo') .attach('image', fs.readFileSync(__dirname + '/resources/IMG_86425.jpg'), 'IMG_86425.jpg') .set('Content-Type','image/jpeg') .end((err, res) => { should.equal(err, null); res.status.should.equal(200); res.should.be.json; done(); }); 问题是attach()固然好像把内容types更新为multipart表单数据,尽pipe我试图用image / jpeg来搭配它。 有什么我们可以做,以覆盖attach()的行为还是有任何其他方式,我可以发布二进制数据到我的function。 谢谢

我可以让柴的expect.to.thot.throw同步吗?

我有一个代码片段,我正在Chai和Pacttesting。 它看起来像这样: var myVerify = () => { provider.verify().then(() => { console.log('B verified') done() }) } expect(myVerify).to.not.throw() 这样做是有效的,但是在继续进行testing之前,要做一个包装函数来确保我等待Pact的validation完成。 协议有一些内部状态,完成后会清除。 如果我只是打电话给这个: 期待(provider.verify())。to.not.throw() 那么它将与其他testing冲突。 这段代码似乎对我很好,但是非常混乱。 它有一个更简单的方法来完成这个?

事件没有捕获我的testing与残桩function

我遇到了一个我不明白的问题。 我发出的事件在我的testing中没有被捕获。 这是下面的代码( event.js ): var util = require('util'), proc = require('child_process'), EventEmitter = require('events').EventEmitter; var Event = function() { var _self = this; proc.exec('ls -l', function(error, stdout, stderr) { _self.emit('test'); console.log('emitted'); }); }; util.inherits(Event, EventEmitter); module.exports = Event; 而相应的testing: var proc = require('child_process'), sinon = require('sinon'), chai = require('chai'), expect = chai.expect, Event = […]

节点模块导出返回未定义

我想创build一个节点模块来抓取一些post,但我得到一个未定义的错误。 Index.js var request = require('request'); function getPosts() { var options = { url: 'https://myapi.com/posts.json', headers: { 'User-Agent': 'request' } }; function callback(error, response, body) { if (!error && response.statusCode == 200) { return JSON.parse(body); } } request(options, callback); } exports.posts = getPosts; testing/ index.js var should = require('chai').should(), myModule = require('../index'); describe('Posts call', function […]

未捕获的SyntaxError:意外的标记{

我试图写一个柴testing,我所做的只是stream一些audio,并得到一个简单的回应: {} ,出于某种原因,我得到这个错误Uncaught SyntaxError: Unexpected token {当我pipe我的fsstream到req ,如果我删除pipe道,我没有那个streamtesting工作正常。 服务器代码: router.post('/', function (clientRequest, clientResponse) { clientRequest.on('end', function () {//when done streaming audio console.log('im at the end>>>>>'); clientResponse.setHeader('Content-Type', 'application/json'); //I've tried removing that: same result clientResponse.json({}); clientResponse.end(); //I've tried removing that: same result }); //end clientRequest.on('end',) }); testing代码: var app = require('./app'); describe('server', function() { this.timeout(10000); it('should […]