在Jasmine测试中模拟Stripe错误? [英] Mock for Stripe error in Jasmine tests?
本文介绍了在Jasmine测试中模拟Stripe错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码在测试环境中引发错误,因为未定义 StripeCheckout
:
The following code is raising an error in the test environment because StripeCheckout
is not defined:
var handler = StripeCheckout.configure({
key: 'pk_test_...',
image: '/images/marketplace.png',
token: function(token) {
process(token);
}
});
如何创建Stripe Mock?
How to create a Stripe Mock?
我认为这样的事情可能有用:
I thought something like this might work:
function StripeMock(){
}
StripeMock.prototype.configure = function( config ){
console.log('configure');
}
var StripeCheckout = new StripeMock();
但是我得到 TypeError:'undefined'不是对象
。
那么,模拟StripeCheckout对象的好方法是什么?
So, what is a good way to mock the StripeCheckout object?
推荐答案
间谍可能是一个更好的主意,但它使用JS函数:
Spies would probably be a better idea, but got it working with JS functions:
function StripeMock(){
}
StripeMock.prototype.configure = function( config ){
console.log('Stripe Mock init.');
return new Handler();
}
function Handler(){
}
Handler.prototype.open = function(params){
console.log('Stripe Mock handler opened.')
}
Handler.prototype.close = function(){
}
var StripeCheckout = new StripeMock();
这篇关于在Jasmine测试中模拟Stripe错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文