Tag: mocha

Cloudant NodeJS出现意外的“server_admin required”错误

我通过Node.JS模块使用Cloudant服务,凭借通过Bluemix VCAP_SERVICES(或本地副本)提供的凭据。 该实例是使用创build的 var Cloudant = require('cloudant'); // var cloudantCreds obtained from process.env.VCAP_SERVICES var username = cloudantCreds.username; var password = cloudantCreds.password; var cloudant = Cloudant({ account:username, password:password }); 我写了一个函数,当用户请求时会自动创build/删除一个数据库,并成功地工作。 这在内部使用 cloudant.db.create(databaseName, function(err, res){ // Handle }); 不过,最近我得到一个错误: 'server_admin access is required for this request' 我只使用一组凭据和一个帐户。 在curl的命令行中使用这些凭据可以让我成功地创build/删除数据库,但似乎无法通过node.js模块来完成此操作。 据我记得,我没有改变任何有关我的Node.js服务器的这个function的代码。 什么导致我现在需要server_admin访问? 从错误消息的性质,我大概authentication,但未经授权?

Zombie.js jQuery加载错误'j.getClientRects不是一个函数'

所以首先我已经阅读了这个堆栈溢出问题,它看起来不像我的同一个问题。 基本上我试图使用Mocha和Zombie.js在我的Node.js网站上运行一些testing。 我试图检查,看看我是否可以创build一个用户。 最后我想检查一下,看看我的bootstrap模式是否存在。 基本上我有引导模式包装在EJS if语句,所以有挑战性的机会,它可能不存在。 所以这就是为什么我试图运行testing。 但是目前它甚至没有使用browser.assert.success(); 所以我现在只是试图解决这个问题,然后继续检查元素。 browser.visit('/login', function() { browser.fill('email', 'test1@test.com'); browser.fill('password', 'testtest'); browser.pressButton('Login').then(function() { browser.assert.success(); }).then(done, done); }); 在这种情况下,我应该在浏览器当前所在的页面上运行以下代码。 <script> $("#paymentModal").modal('show'); </script> 运行这个unit testing时,会给我下面的错误。 https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js:3 }return c}function Q(a){var b;for(b in a)if(("data"!==b||!n.isEmptyObject(a[b]))&&"toJSON"!==b)return!1;return!0}function R(a,b,d,e){if(M(a)){var f,g,h=n.expando,i=a.nodeType,j=i?n.cache:a,k=i?a[h]:a[h]&&h;if(k&&j[k]&&(e||j[k].data)||void 0!==d||"string"!=typeof b)return k||(k=i?a[h]=c.pop()||n.guid++:h),j[k]||(j[k]=i?{}:{toJSON:n.noop}),"object"!=typeof b&&"function"!=typeof b||(e?j[k]=n.extend(j[k],b):j[k].data=n.extend(j[k].data,b)),g=j[k],e||(g.data||(g.data={}),g=g.data),void 0!==d&&(g[n.camelCase(b)]=d),"string"==typeof b?(f=g[b],null==f&&(f=g[n.camelCase(b)])):f=g,f}}function S(a,b,c){if(M(a)){var d,e,f=a.nodeType,g=f?n.cache:a,h=f?a[n.expando]:n.expando;if(g[h]){if(b&&(d=c?g[h]:g[h].data)){n.isArray(b)?b=b.concat(n.map(b,n.camelCase)):b in d?b=[b]:(b=n.camelCase(b),b=b in d?[b]:b.split(" ")),e=b.length;while(e–)delete d[b[e]];if(c?!Q(d):!n.isEmptyObject(d))return}(c||(delete g[h].data,Q(g[h])))&&(f?n.cleanData([a],!0):l.deleteExpan TypeError: j.getClientRects […]

与摩卡手表一起使用时,Sinon存根有奇怪的performance

所以这里是我们的基本设置 src/MyComponent.js import actions from `src/actions` export const mapDispatchToProps = dispatch => { return { onClick: () => { dispatch(actions.myAction()) } } } src/actions.js const actions = { myAction: () => () => … } export default actions src/MyComponentTest.js import sinon from 'sinon' import actions from 'src/actions' import { mapDispatchToProps } from 'src/MyComponent' describe('onClickTests, () […]

Immutablejs Map.update打破了unit testing

我试图拿起Redux和我下面的教程使用ImmutableJs。 我对ImmutableJs是完全陌生的,我只是想通过API文档去实现。 我的练习应用比教程复杂得多,所以我走了一段路,可能已经迷路了。 任何时候我使用Map.update()方法,我无法find一种方法来成功地testing我的代码。 这是我写的一个testing,试图找出什么是错的: import chai, {expect} from 'chai'; import chaiImmutable from 'chai-immutable'; import {List, Map} from 'immutable'; chai.use(chaiImmutable); describe("Immutable Test Issues", () => { it("should present accurate immutable equality", () => { // — Maps with Lists match just fine const a1 = Map({ test: 1, args: List([1, 2]) }); const a2 = […]

如何通过摩卡和柴匹配在网页上呈现的特定string

我正在使用mocha和chai包在我的Node JS应用程序中构build一个testing套件。 到目前为止,我通过检查页面成功呈现时返回的状态码(200)来validationtesting用例是否合格/不合格。 如何根据我在页面上呈现的内容来validation页面是否合格/不合格。 例如,如果页面显示“欢迎使用Express”,我想匹配“Welcome”或“Express”中的任何一个来validation它是否合格。 以下是我的代码检查状态代码的片段: describe('Home Page', () => { it('This is the Home page', (done)=> { chai.request(server) .get('/home') .end((error, respond) => { expect(respond.statusCode).to.equal(200); done(); }); }); });

使用我的Node.js REST API设置Mocha / ChaiHttp单元时遇到问题

我正在尝试使用mocha和chaihttp为我的node.js REST API设置unit testing,但是我应该通过的示例testing似乎失败了。 我的unit testing代码在这里: var express = require('express'); var router = express.Router(); var chai = require("chai"); var chaiHttp = require('chai-http'); chai.use(chaiHttp); describe("Test", function() { it('Simple test', function(done) { chai.request('http://localhost:3000/') .get('/') .end(function(err, res) { chai.expect(res).to.have.status(200); done(); }); }); }); 运行testing时出现的错误: 1) Test Simple test: Uncaught AssertionError: expected { Object (domain, _events, …) } to […]

在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机上也出现分段错误。

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") […]

nodemon应用程序崩溃时运行此“npm运行testing手表”

在我的package.json文件中,我编写了这个运行nodemon: "scripts": { "test": "mocha server/**/*.test.js", "test-watch": "nodemon –exec 'npm test'" },这个错误在terminal显示: > node-todo-api@1.0.0 test-watch D:\nodepractice\node-todo-api > nodemon –exec 'npm test' [nodemon] 1.12.0 [nodemon] to restart at any time, enter `rs` [nodemon] watching: *.* [nodemon] starting `'npm test'` ''npm' is not recognized as an internal or external command, operable program or batch file. [nodemon] app […]