首页 文章
  • 11 votes
     answers
     views

    测试在Mocha / Chai中拒绝了承诺

    我有一个拒绝承诺的课程: Sync.prototype.doCall = function(verb, method, data) { var self = this; self.client = P.promisifyAll(new Client()); var res = this.queue.then(function() { return self.client.c...
  • 0 votes
     answers
     views

    Vue js Jest异步测试

    我有问题 . 当我挂载组件Jest没有等待解决promises.fetch API没有在生命周期mount中执行 . 我已经尝试了flushPromises但没有工作 . 我已经尝试了mocha但同样的问题 . describe('HelloWorld.vue', () => { it('should render correct contents', async () => { ...
  • 204 votes
     answers
     views

    Mocha / Chai期待 . 没有 grab 抛出的错误

    我'm having issues getting Chai' s expect.to.throw 在我的node.js应用程序的测试中工作 . 测试在抛出错误时保持失败,但是如果我在try中包装测试用例并捕获并断言捕获的错误,则它可以工作 . expect.to.throw 不能像我想的那样工作吗? it('should throw an error if you try to get an ...
  • 12 votes
     answers
     views

    使用Mocha和Chai-as-Promised测试被拒绝承诺的特定属性

    我正在尝试使用Chai-as-Promised,Mocha和"should"方言来测试被拒绝的Promise的细节 . 承诺由bluebird实施 . 这很好用: it('it should be rejected when given bad credentials', function () { var promiseOfUsers = db.auth("...
  • 1 votes
     answers
     views

    与mocha / chai和ES6 Promise断言的奇怪失败

    我遇到了ES6 Promise和一些mocha / chai测试的奇怪行为 . 考虑以下 foo() 函数返回一个promise,我想测试两件事: 它返回一个promise(所以,一个对象) 它在失败时抛出异常(以及对象) . 问题是,在测试 expect(..).to.be.an('object') 两种情况下都失败了,但类型 is object (用 typeof 检查) . ...
  • 0 votes
     answers
     views

    使用Promises测试流星 - 摩卡

    我正在为Meteor JS应用程序编写服务器端单元测试 . 我正在使用推荐的Mocha框架,带有chai断言库 . 使用done()回调链接异步调用时遇到了一些麻烦,所以我决定使用meteor / promise . 我正在使用和johanbrook:publication-collector来收集已发布的集合 . 当我在promise中解析(集合)时,在随后的then()中,我能够在consol...
  • 7 votes
     answers
     views

    如何追踪导致超时的原因?

    我正在使用Mocha进行一些测试 . 当我进入一组特定的测试时: describe "Results Summaries", -> before (done) -> Testing.use("surveyplanet_test") Testing.initialUsers -> Testing.cle...
  • 5 votes
     answers
     views

    Mocha supertest断言:测试失败时打印响应体

    我正在使用mocha,supertest和assert来测试我的Express应用程序 . My Express应用程序在开发模式下运行,因此只要请求失败,它就会以JSON形式返回有用的调试信息 . 我想在我的测试套件中打印这些数据,但仅在测试失败时才打印 . 我的一个测试的例子(在CoffeeScript中): assert = require "assert" re...
  • 1 votes
     answers
     views

    Mocha Chai HTTP发布请求无效

    以下测试不适用于mocha-chai,它能够获取输入请求但会抛出错误消息 . it('/hb : ', function (done) { return chai.request(app) .post('/hb') .send({"a":1 }) .then...
  • -1 votes
     answers
     views

    从gulp运行时,摩卡测试失败

    我已经为我的应用程序的服务级别类开发了一套测试,并且当它们在mocha中运行时都会通过,即: mocha testfile.js 但是当我从gulp运行它们时,我在其中一个文件中的每个测试都会出现超时错误: 1)预订服务应创建预订:错误:超过2000毫秒的超时 . 确保在此测试中调用done()回调 . 2)预订服务应取消预订:错误:超过2000ms超时 . 确保在此测试中调用done()回调 ....
  • 0 votes
     answers
     views

    nodeJS Supertest,mocha失败错误:超出2000ms超时

    我的"/todos"路由工作,实际上我可以在 end 回调中的if语句之后调用done()并且它'll update the database, but when I add a my mongodb query to verfiy it has been added, it doesn' t更新我的数据库它给了我 错误:超过2000毫秒的超时 . 确保在此测试中调用done(...
  • 79 votes
     answers
     views

    有没有办法让Chai使用异步Mocha测试?

    我正在使用浏览器运行器在Mocha中运行一些异步测试,我正在尝试使用Chai的期望样式断言: window.expect = chai.expect; describe('my test', function() { it('should do something', function (done) { setTimeout(function () { expect(tru...
  • 4 votes
     answers
     views

    AngularJS,Mocha,Karma . 测试控制器,模拟服务承诺

    我正在使用AngularJS,Karma,Mocha,Chai,Chai-as-promise,Sinon .我正在尝试下面的控制器 . 我无法模拟服务User并测试控制器中的.then()部分 . 控制器代码 .controller('SignupPhoneCtrl', function(User, $scope) { $scope.sendPhoneNumber = function(co...
  • 3 votes
     answers
     views

    使用Mocha时,超时超时错误

    在使用 Mocha 进行测试时,我在运行server.test.js时遇到以下错误 1)“每个”钩子之前“应该得到所有待办事项”:错误:超过2000毫秒超时 . 对于异步测试和挂钩,确保调用“done()”;如果返回Promise,请确保它已解决 . server.test.js const expect = require('expect'); const request = requir...
  • 0 votes
     answers
     views

    使用Mocha超时错误进行架构测试

    这是我的架构: const mongoose = require('mongoose'); const Schema = mongoose.Schema; //INDEX PAGE SCHEMA const IndexSchema = new Schema({ bio: String }); const IndexPageData = mongoose.model('indexpagedat...
  • 2 votes
     answers
     views

    异步Mocha测试(使用Chai断言库)应该失败,但标记为传递

    我在TypeScript中使用mocha测试框架和chai断言库编写了一些测试(我对其中的所有3个都是新的),并且发现错误被抛出并且在下面的代码中调用了assert.fail() . 但是,测试仍然标记为通过 . 我很困惑为什么会发生这种情况,如果我对承诺做错了 . 此外,如下所示,还有一个UnhandledPromiseRejectionWarning . 我不明白为什么这被标记为未处理,因为我...
  • 3 votes
     answers
     views

    mocha done()和async await的矛盾问题

    我有以下测试用例: it("should pass the test", async function (done) { await asyncFunction(); true.should.eq(true); done(); }); 运行它断言: 错误:分辨率方法过度指定 . 指定回调或返回Promise;不是都 ....
  • 0 votes
     answers
     views

    处理承诺拒绝与柴

    我有以下验证函数检查用户是否存在: validate.user = async (user, password) => { const matches = await bcrypt.compare(password, user.password); if (matches) return user; if (!matches) { return val...
  • 0 votes
     answers
     views

    使用Mocha和Superagent在裸Node.js应用程序中测试帖子

    我希望那一天能找到你 . 所以我正在尝试在Node中构建一些TDD chops,为此我已经构建了一个运行简单的GET和POST请求的超级骨架应用程序 . 它所做的只是提供世界上最简单的形式,然后将用户输入的内容放入此表单并将其放在屏幕上 . 这是原始节点,不涉及框架 . 我正在使用Mocha和Superagent进行测试,并且在POST测试中遇到困难 . 这是我的应用程序: var http = ...
  • 1 votes
     answers
     views

    在Mocha Supertest中进行404测试时出现'Body Parse'错误

    我正在尝试编写测试以确保我的Express API正确地为各种方案返回正确的HTTP状态代码 . 我在测试中使用Mocha和Supertest来请求API . 现在我得到了非常意外的结果,详情如下 . 使用:Express,body-parser,Sequelize,Mocha,Supertest GET / users /:id models.User.find(req.params.id).c...
  • 0 votes
     answers
     views

    摩卡测试 . 超时2000ms

    我做错了什么?我正在尝试将手机保存到我的数据库,但是摩卡说超过了2000毫秒的超时 . 我的手机架构 const mongoose = require('mongoose'); const Schema = mongoose.Schema; const phoneSchema = new Schema({ company: String, modelname: String, ...
  • 0 votes
     answers
     views

    返回承诺时摩卡超过2000毫秒超时[重复]

    这个问题在这里已有答案: Change default timeout for mocha 4个答案 我正在尝试测试我的Express.js控制器,但每次经常遇到mocha超时告诉我的问题 . 文档(https://mochajs.org/#working-with-promises)和答案在这里:https://stackoverflow.com/a/26572442/1646372声明我可...
  • 0 votes
     answers
     views

    单元测试Rxjs 5

    我正在尝试使用mocha和chai为我的可观察方法编写测试,该方法调用服务器并返回一些json数据 . 但是,当我运行测试时,我收到以下错误: Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensur...
  • 0 votes
     answers
     views

    尽管使用done()进行异步调用,如何摆脱mocha-chai测试中的超时错误?

    我在mocha测试套件中使用setTimeout来插入一个20秒的延迟,然后在describe块中进行it()的最后一次调用 . 虽然,我正在使用done(),但我仍然在终端上得到以下错误: 错误:超过2000毫秒的超时 . 对于异步测试和挂钩,确保调用“done()”;如果返回一个promise,请确保它解决错误:超过2000ms的超时 . 对于异步测试和挂钩,确保调用“done()”;如果返回...
  • 0 votes
     answers
     views

    使用文档但完全混淆了...... mongoose Model#save

    我正在尝试返回特定的状态代码,例如,409 Conflict . 我用了Model#save docs 编辑: I am not trying to solve the error, it is deliberate. 根据文档,回调有三个参数:err,product和numAffected . EDIT: I wrote this code wrong and I edited. Either ...
  • 0 votes
     answers
     views

    使用Mocha测试Typescript

    我正在尝试使用Mocha测试在Typescript中编写的NodeJS项目,我从绝对类型中获取了mocha.d.ts文件 https://github.com/borisyankov/DefinitelyTyped/blob/master/mocha/mocha.d.ts . 这是我在Webstorm中看到的错误: C:/Users/Me/AppData/Roaming/npm/tsc.cmd -...
  • 2 votes
     answers
     views

    使用Mocha进行Vuejs测试:组件未安装到元素上

    我对使用VueJS开发和使用Mocha进行测试(无头使用)相对较新,我故意不使用vue-cli来更好地理解一切是如何工作的 . 我有一套功能相当好的单元测试(获取请求,获取/设置道具等),直到我需要检查DOM中的某些内容 . 看起来组件已成功创建,但它们未安装到元素上 . 我正在使用JSDom为无头测试创建DOM上下文,如我的_setup.js中所示: global.Vue = require('...
  • 0 votes
     answers
     views

    状态变化后测试反应组分

    如何测试以下组件? import React from "react"; class ModuleLoader extends React.Component { state = { Module: null }; componentDidMount() {...
  • 208 votes
     answers
     views

    chai测试数组相等不能按预期工作

    为什么以下失败? expect([0,0]).to.equal([0,0]); 什么是测试的正确方法?
  • 2 votes
     answers
     views

    使用mocha在node.js中测试 - 新手

    我已经开始在我的JS项目中实现TDD了 . 我为此目的实现了mocha . 因为这些是我做的第一步: 已安装node.js. 在我的项目中全局和本地安装了mocha . 写了package.json设置依赖项 . 写了makefile . 写了.gitignore以避免上传node_modules文件夹 . 文件夹结构 项目 js ---- filetotest.js ...

热门问题