-
2 votesanswersviews
如何将Sinon.JS Spy 函数指定为类定义的一部分?
我正在使用Require.js和Backbone.Marionette编写Backbone.js应用程序,并使用Mocha与Chai,Sinon和Sinon-Chai进行测试 . 我一般使用Jarrod Overson's Backbone Marionette with Require.JS TODO sample作为应用程序结构的参考,Jim Newbery's posts on testin... -
0 votesanswersviews
Mocha&Sinon - 窥探从Node异步回调中调用的函数?
Problem summary: 我想测试 redisCallback() ,它是在NodeJS异步回调中调用的(参见下面的代码),已使用预期的参数调用预期的次数 . background information (skip if TL;DR): 我四处搜索但只找到了QUnit的解决方案 . 我不确定Mocha Sinon相当于这种困境的等价物 . 在我目前的测试中,Chai断言以 Asserti... -
0 votesanswersviews
测试使用Jasmine和Sinon返回promise的AngularJS Controller方法
我'm trying to test an Angular controller method that returns a promise. I stubbed out the promise-returning method (using a sinon stub), but when the promise is resolved (fulfilled), the registered su... -
2 votesanswersviews
我如何期望在nodejs中使用sinon,mocha和chai的特定args调用函数?
我一直有一个问题,试图确保用我传入的args调用 Q.ninvoke . 我是新手测试Sinon,Mocha和Chai . 我已经尝试了我在网上找到的所有东西,现在已经有两天了,我仍然无法获得我的测试通行证 . 我究竟做错了什么? 这是我的测试代码 . var cuid = require('cuid'); var fs = require('fs'); var Q = require('q')... -
0 votesanswersviews
诗乃 Spy 没有触发
我无法追查为什么没有触发一个罪人 Spy . 在下面的测试中,两个控制台语句都报告为false,因此没有调用任何方法(如果有错误) . 这是我的一个mocha测试通常看起来像: describe('Post Controller', function () { var controller = require('../controllers/PostController'), r... -
0 votesanswersviews
Object.observe有50%的时间工作,为什么?还有其他关于重构这个的建议
我目前正在使用mocha,chai和sinon测试此代码 import passport from 'passport'; import jwt from 'jsonwebtoken'; import expressJwt from 'express-jwt'; import compose from 'composable-middleware'; import Use... -
0 votesanswersviews
如何连接Backbone,Mocha,Chai,Require.js和Sinon
我目前正在尝试基于Backbone为我的应用设置测试环境 . 我想单元测试一些功能 . 但我必须承认我在连接不同组件时遇到问题 . 我正在使用Backbone,Mocha,Chai,expect.js,require.js和Sinon . 该应用程序基本上是与Yeoman Build 的 . 我现在 Build 的是(根据我非常喜欢的这个教程:https://puigcerber.com/2013... -
1 votesanswersviews
Sinon Fakeserver测试不同的组件/文件 - 没有请求?
我正在使用Mocha / Chai / Sinon测试一个React组件,并使用 renderedComponent.getTodos(callback) 之类的东西在不同的文件中调用AJAX请求 . 我正在传递类似于Sinon FakeServer tutorial的回调 . 但是,我收到一个奇怪的语法错误,导致不调用回调,因此 server.requests 为空 . 我知道我问了一个类似的问... -
10 votesanswersviews
使用酶测试React组件状态的变化并监视实例方法
我正在开发一个包装器组件,用于在React中平滑地加载图像 . 我使用含有mocha,chai和sinon的酶对我的组件进行单元测试 . 在这里的测试中,我试图测试: 加载图像时会更新 组件的状态 调用了组件上的 onLoad 实例方法 const wrapper = shallow( ); const onLoad = wrapper.find('img').props().onL... -
-1 votesanswersviews
NodeJS:如何在使用Mocha,Chai,Sinon进行测试时验证promise内部的函数调用?
我是使用Mocha,Chai和Sinon在NodeJS中进行单元测试的新手 . 我一直在尝试为API endpoints 编写一个单元测试用例,如果在Promise解决方案中从API调用 res.status(200).send(); ,我正在努力测试 . 以下是代码: controller.js - 具有单元测试功能 const User = require("./user_mod... -
0 votesanswersviews
测试请求(摩卡柴,超级) . 我不知所措
I'm a noob with Node.js, mocha,chai, sinon and supertest. This is the function I have and need to test. It is in .js file that has const request = require('request'); at the beginning and exports mod... -
1 votesanswersviews
使用sinon.js spy()来包装现有函数
我是JavaScript测试的新手,在尝试使用sinon.js监视现有函数时遇到了一个问题 . 假设我有一个叫做的函数 nsClientInfectionControlIndex.handleEditButton(); 看起来像 var nsClientInfectionControlIndex = { showQtipError : function (message) { ///&... -
5 votesanswersviews
Sinon - 如何存根嵌套函数?
抱歉,如果这是一个简单的问题,我对Node和Sinon来说相对较新 . 我正在努力弄清楚如何断言在Nodejs中调用嵌套的异步函数 . 我正在使用摩卡,柴,sinon和请求(https://github.com/request/request)但我认为我遗漏了一些基本的短截部分 . my_app.js中的示例 - var request = require('request'); functio... -
1 votesanswersviews
摩卡测试不会使用Sinon存根解决承诺
我正在使用Mocha来测试一个在其中有异步方法的方法 . 我正在与Sinon存在这种依赖关系,并返回一个已解决的承诺 . 但承诺永远不会得到解决,或者至少在断言运行时它尚未解决 . 这是测试中的方法 function identify(traits) { //THIS GETS CALLED SUCCESSFULLY userService.get().then(function(user... -
5 votesanswersviews
如何对一个调用另一个返回promise的函数进行单元测试?
我有一个使用express 4的node.js应用程序,这是我的控制器: var service = require('./category.service'); module.exports = { findAll: (request, response) => { service.findAll().then((categories) => { respo... -
0 votesanswersviews
单元测试请求 - 承诺,promise()不是函数
我试图使用 request-promise 对sinon / mocha进行单元测试 . 我附上 .promise() 以允许访问所有Bluebird承诺方法 . 根据 request-promise 自述文件: rp(...).promise() or e.g. rp.head(...).promise() which returns the underlying promise so you ... -
1 votesanswersviews
跟踪使用Sinon / Mocha调用方法的次数
我正在使用Mocha / Sinon编写测试,以确保我创建的 async tryAtMost 函数调用Promise并且只重试该承诺 X 次 . 我的 tryAtMost 函数看起来像: async tryAtMost(options, promise, maxRetries, retryInterval = 0) { return new Promise(async (resolve, ... -
3 votesanswersviews
Objection.js Stubbing与Sinon链接的“whereIn”方法
尝试使用Sinon存根链接的knex查询 . 查询如下所示 const result = await TableModel .query() .whereIn('id', idList) .whereIn('value', valueList); 通常我使用一个我创建的辅助函数,它返回一个模型实例,每个方法都存根,返回 this ,就像这样 for (const method of ... -
0 votesanswersviews
当我开始使用异步中间件时,与Sinon的ExpressJS单元测试中断了
使用ExpressJS 4.16.4并使用Mocha,Chai和Sinon进行单元测试 . 我的一条子路线看起来像这样: const router = require('express').Router(); const controller = require('./announcement.controller'); const auth = require('../../auth/auth.... -
0 votesanswersviews
Sinon不会使用参数模拟为GET提供的URL
我正在尝试为Angular应用程序中的服务开发测试并面临一些问题 . 这是服务代码: /** * Sends http request to get client states and territories available for specific vertical * * @param {number} vertical id of specific vertical. The fo... -
8 votesanswersviews
使用Enzyme测试React组件中<iframe>的内容
我写了一个简单的React组件来呈现 <iframe> : export class Iframe extends React.component { render() { return <iframe src={ this.props.src } />; } } 我试图通过检查 <iframe> 中加载 src 的内容是否正确填... -
0 votesanswersviews
如何测试返回promises的嵌套vuex操作?
这是我的组件中的代码和我当前的测试: // component script import { mapActions } from 'vuex' export default { name: 'foo', mounted () { this.firstMethod() .then(() => { this.secondMethod() ... -
0 votesanswersviews
Vuex采用Sinon进行测试
被困,无法解决这个问题....我想要做的就是确保我的Vue组件在安装时调用存储操作 . 这是一个简单的测试,它在Vuex商店中模拟getUsers()动作 . import {shallow, createLocalVue} from '@vue/test-utils'; import UserManager from '../modules/UserManager/components/inde... -
0 votesanswersviews
使用Sinon时,使用debounceTime错误来反应组件
我有以下React组件 探索在这里输入代码 class IncrementalSearch extends React.Component { constructor(props) { super(props); this.onSearch$ = new Subject(); this.onChange = this.onChange.bi... -
0 votesanswersviews
酶不会'render, mount, or shallow'一个组件,因为依赖是未定义的
我想弄清楚为什么我的测试不会运行 . 我有一个React功能组件,它包含一个样式组件,它使用自定义方法生成一个媒体查询,该查询将被导入为css帮助文件 . 我得到了 TypeError: Cannot read property 'medium' of undefined . 这是我的代码 . css / index.js export const media = (function(){ ... -
3 votesanswersviews
如何在Enzyme / React中测试包含连接到Redux的组件的组件?
在测试 React components 时,在 Enzyme 中连接到 Redux 时,有一个熟悉的问题 . 您可能遇到过此错误: Invariant Violation: Could not find "store" in either the context or props of "Connect(YourComponent) 这是 resolved 通... -
7 votesanswersviews
node js单元测试:mocking需要依赖
我在将以下设置的单元测试编写为jira.js文件(在node.js模块中)时遇到问题: var rest = require('restler'); // https://www.npmjs.com/package/restler module.exports = function (conf) { var exported = {}; exported.getIssue = ... -
10 votesanswersviews
用Sinon保存Mongoose模型的实例方法
我正在尝试使用Mongoose模型测试我用来保存小部件的服务功能 . 我想在我的模型上存根保存实例方法,但我无法找到一个好的解决方案 . 我见过其他建议,但似乎都没有完整 . 见...... this和this . 这是我的模特...... // widget.js var mongoose = require('mongoose'); var widgetSchema = mongoose.... -
14 votesanswersviews
模拟/存根Mongoose模型保存方法
给出一个简单的Mongoose模型: import mongoose, { Schema } from 'mongoose'; const PostSchema = Schema({ title: { type: String }, postDate: { type: Date, default: Date.now } }, { timestamps: true }); cons... -
2 votesanswersviews
对Mongoose模型的虚拟属性进行拼接
有没有办法存根Mongoose模型的虚拟属性? 假设 Problem 是模型类, difficulty 是虚拟属性 . delete Problem.prototype.difficulty 返回false,属性仍然存在,所以我不能用我想要的任何值替换它 . 我也试过了 var p = new Problem(); delete p.difficulty; p.difficulty = Pro...