- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在尝试 stub nodejs stripe api使用 sinon,使用如下所示的测试来测试客户的创建:
var sinon = require('sinon');
var stripe = require('stripe');
var controller = require('../my-controller');
var stub = sinon.stub(stripe.customers, 'create');
stub.create.yields([null, {id: 'xyz789'}]);
//stub.create.yields(null, {id: 'xyz789'}); //same result with or without array
controller.post(req, {}, done);
我的理解是 stub.create.yields
应该调用第一个回调,并将它(在本例中)传递给 null,然后传递一个 id 为 xyz789 的对象这可能是我弄错的地方
在我的“ Controller ”中,我有以下内容:
exports.post = function(req, res, next) {
stripe.customers.create({
card: req.body.stripeToken,
plan: 'standard1month',
email: req.body.email
}, function(err, customer) {
console.log('ERR = ', err)
console.log('CUSTOMER = ', customer)
错误,客户都未定义。
我是不是做错了什么?
编辑
我认为问题可能出在这里:(条纹文档)
var stripe = require('stripe')(' your stripe API key ');
因此,stripe
构造函数接受一个 api key
在我的测试中,我没有提供: var 条纹 = require('条纹');
但是在我的 Controller 中,我有:
var stripe = require('stripe')('my-key-from-config');
因此,根据您的示例,我有:
test.js:
var controller = require('./controller');
var sinon = require('sinon');
var stripe = require('stripe')('test');
var stub = sinon.stub(stripe.customers, 'create');
stub.yields(null, {id: 'xyz789'});
//stub.create.yields(null, {id: 'xyz789'}); //same result with or without array
controller.post({}, {}, function(){});
controller.js
var stripe = require('stripe')('my-key-from-config');
var controller = {
post: function (req, res, done) {
stripe.customers.create({
card: req.body,
plan: 'standard1month',
}, function(err, customer) {
console.log('ERR = ', err);
console.log('CUSTOMER = ', customer);
});
}
}
module.exports = controller;
最佳答案
当你这样做时:
var stripe = require('stripe')('my-key-from-config');
stripe 库动态创建customer
和其他对象。因此,当您将其存入一个文件时:
test.js
var stripe = require('stripe')('test');
var stub = sinon.stub(stripe.customers, 'create');
然后您的 Controller 创建另一个 stripe
实例以在另一个文件中使用:
controller.js
var stripe = require('stripe')('my-key-from-config');
var controller = { ... }
测试的 stub 版本对 Controller 的版本没有影响。
所以....
您需要将 stripe
的测试实例注入(inject)到您的 Controller 中,或者使用类似 nock 的库在 http 级别模拟事物,如下所示:
nock('https://api.stripe.com:443')
.post('/v1/customers', "email=user1%40example.com&card=tok_5I6lor706YkUbj")
.reply 200,
object: 'customer'
id: 'cus_somestripeid'
关于javascript - 用 sinon stub 条纹 - 使用 stub.yields,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22645216/
我正在尝试重用在 jsp 中设置并在 Stripes 布局渲染中使用的变量。 主页:/index.jsp 布局渲染页面:/jsp/widgets/signin/oAuthUrl.jsp 我的/jsp/
我已经测试了几个小时,但我似乎无法让边框图像做我想做的事。 我正在尝试向带有水平条纹的 div 添加底部边框。即2px灰,2px白,2px灰;即灰色和白色条纹。 像这样: 这是我目前所拥有的: .bo
我正在尝试使用一个不错的响应式网站模板 http://html5up.net/striped并遇到了一些问题。我已经设置了一个非常基本的测试。我 downloaded条纹包,在陨石应用程序中创建了一个
为什么这行不通? (例如,为什么脚本没有实际运行并创建付款按钮,就像它不在指令中那样。) .directive('stripeForm', ['$log', function($log) { re
我有一个表(Maintable),里面有信息。此外,每个 tr 都有一个子表,其中包含可以在需要时折叠的更多信息。现在,我希望对 maintable 中的 tr 进行 strip 化。我尝试使用:
我有一个表,其中包含由类标记的行。这些行应该是斑马条纹。需要注意的是它们并不总是连续的。 我尝试过按表和类名进行匹配,但最终结果总是不正确。发生的情况是, strip 化将应用于表级别,然后仅在具有该
原始表(http://highspeedbroadband.com.my/home-package/comparison-chart-for-home-package/) 我想修改下图中突出显示的原始
我有以下 html 文件: .table-striped { padding: 0; margin: 0;
这个问题在这里已经有了答案: CSS technique for a horizontal line with words in the middle (34 个答案) 关闭 9 年前。
我有一个 bootstrap 条纹表 ( .table-striped > tbody > tr:nth-of-type(odd){background-color: #f9f9f9;} ),我正在使
我对 Spring MVC 很有经验,正在试用 Stripes 以决定是否在新项目中试用它。 在 Spring MVC 中,我将准备模型数据并将其传递给 View ,方法是将其添加到由我的 Contr
我正在尝试使用 Rails 在 Stripe 中创建一次一次性充电。我收到以下错误: Stripe::InvalidRequestError (No such token: tok_18nnwSJ6t
在 Stripes 中,如果存在错误的操作类映射,Stripes 的默认行为是将控件转发到发出请求的同一个 JSP,并给出完整的错误堆栈。 我计划修改此行为,并希望在出现错误时提供更加用户友好的消息。
我的问题分为两部分: 如何使用 spark 设置(微调)高级 ORC 参数? 各种帖子显示可能存在问题Spark Small ORC Stripes , How to set ORC stripe s
我有一个 Stripes 框架问题。 这个重定向页面在注解方法之前? 类似于: @Before public void test() { String login=(String)context.
我想使用 Jest 测试我的 nodejs 代码。在我的代码中,我使用了条纹。 当需要条纹时,你必须使用这一行 const stripe=require('stripe')("apikey"); 为了
在这个例子中: https://jsfiddle.net/ywb77uhv/ 为什么将 strip 路径颜色更改为白色以外的颜色会破坏渲染?如何能够更改路径颜色? #stri
我在获取斜条纹背景以在 Chrome 中很好地显示时遇到了问题。 background-image: repeating-linear-gradient(-45deg, rgba(0,0,0,0.1)
我想在图像上绘制黑白条纹,在图像顶部水平和垂直地每 20 列切换一次,同时保持在图像边界内。到目前为止,我可以获得一个带有 1 像素宽垂直条纹的黑色正方形。我尝试过通过切换东西来至少在水平线上获得细长
所以我最近一直在尝试学习 Stripe API...我进展缓慢,但在处理这些元数据信息时遇到了一些障碍。 我希望实现的是在创建订阅和客户时向订阅添加元数据。 这是创建客户和订阅的原始脚本: $cust
我是一名优秀的程序员,十分优秀!