在我的原始函数中,我需要在同一个沙发登录中向2个不同的数据库发出2个请求。
var cloudant = require('cloudant')(https://cloudant_url);
var userdb = cloudant.db.use('user');
var addrdb = cloudant.db.use('address');
function onChange(username) {
userdb.get(username, function(err,resp) {
var user_id = r
在我的测试代码中,当我检查断言所有nocks都已被调用时,如果没有调用nock (因为默认的错误消息是无用的),我有一个半有用的错误消息来转储出:
try {
assertions(data, result);
if (assertNock !== null) {
// Expect that all mocked calls were made
if (nock.isDone() !== !!assertNock) {
console.error('One or more of your Nock matchers was never called
我有相对简单的摩卡和chai测试设置。不幸的是,当我运行摩卡测试时,肯定会失败的!这是我的测试用例。
var expect = require('chai').expect;
var nock = require('nock');
var request = require('request');
var testUrl = 'http://test.wicked.ti';
var getItems = function(url, callback) {
request.get(url +
我试图掌握工具,以便模拟执行调用的代码中的请求和响应。我使用npm请求作为一个简单的HTTP客户机来请求后端REST、希望库的Chai和运行我的测试的Mocha。下面是用于测试的代码:
var nock = require('nock');
var storyController = require('../modules/storyController');
var getIssueResponse = {
//JSON object that we expect from the API response.
}
it('It sh
您好,在redux的测试文档中,他们有这个例子来测试api调用:
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import * as actions from '../../actions/counter'
import * as types from '../../constants/ActionTypes'
import nock from 'nock'
const middlewares
我有验证response.connection.remoteAddress不是本地IP的应用程序代码,但在使用nock时,response.connection只是一个没有remoteAddress属性的EventEmitter实例。如何修改nock创建的响应? 更新:我最终改用了isPrivate(): it('GET returns a 403 status code when example.com resolved to internal ip', function(done){
const scope = nock('https://example.
我经常在使用Nock时遇到这个错误(Error: Nock: No match for request),但我发现很难快速理解什么不匹配,以便进行调整。
我过去常常使用nock(apiUrl).persist().log(console.log)(),它在这方面做得很好。但是它已经被弃用了,我最近更新了依赖项。因此,我需要适应,但我发现很难掌握对我的调试感兴趣的信息。
如何获得类似于Jest的东西,明显地比较期望的东西,以及为了快速而直接的调试而实际调用的东西?
我有一个ReactJs/Typescript项目的单元测试,该项目引用一个名为nock.js的模块,并使用jest:
import nock from 'nock'
...
afterEach(() => {
nock.cleanAll();
})
当我运行测试时,我在.cleanAll语句中得到一个错误:
TypeError: nock_1.default is not a function
但是,当我将import语句更改为:
var nock = require('nock');
这个问题解决了。我如何才能仍然使用导入而不是需求?这是jest
全新的测试。试图找出为什么摩卡要通过这个测试,而它应该失败。
var assert = require('assert');
var nock = require('nock');
var https = require('https');
describe('thing', function() {
describe('foo', function () {
it('makes the correct https call to API',
如何使用nock模拟delete
这就是我到目前为止所做的:
var nock = require('nock');
var request = require('supertest')("http://localhost:8080");
var expect = require('chai').expect;
describe('Mocked tests for server components', function(){
var mockRequest = nock('http://localhos
目前,我正在学习RxJS,我正在努力弄清楚如何使用nock测试Observable.ajax()。
这是我简化的例子,没有任何断言..。我只想看看nock是否能拦截那个API调用。
import { afterEach, describe, it } from 'mocha';
import nock from 'nock';
import { ajax } from 'rxjs/observable/dom/ajax';
// had to use `crossDomain: true` for it to work in productio