我正在尝试对使用StripeJS
的付款组件进行单元测试。
我将其导入文件'ng-app.js':
stripe: /*@ngInject*/ function ($ocLazyLoad) {
return $ocLazyLoad.load({
type: 'js',
path: 'https://js.stripe.com/v3/'
});
}
在我的付款部分(payment.component.ts
)中,我使用:
import {StripeJS} from 'stripejs';
import {ElementFactory, OnChange, StripeElement} from 'stripejs/element';
还有:
constructor(private fb: FormBuilder, private store: Store<AppState>) {
this.stripe = window.Stripe(window.properties.stripePKs[this.carrier]);
this.createStripeElements(this.stripe.elements());
}
但是我不知道如何在StripeJS
内插入payment.component.spec.ts
。
执行undefined
时,组件为component = fixture.componentInstance;
我的要求是知道如何将测试中的StripeJS
组合为模拟或不模拟,以便我为其余测试成功创建组件。
答案 0 :(得分:0)
我从未使用过stripeJS,因此,我将为您提供一个一般性的答案,如果您需要具体的示例,请在此处或github上发布代码,我们可以为您提供更多详细信息。在进行单元测试之前,您需要了解Jasmine和Karma的工作方式。
在单元测试的导入部分中,确保已导入stripeJS。
在你的UT构造函数有类似
mockstripejs:Mock<StripeJS>
在要进行测试的测试类中,您需要设置要测试的条带操作,如果它类似于stripe.getcardprovider
,则需要诸如mockstripejs.setup(x=>x.getcardprovider).is(cardProvider.Object)
的设置
其中cardProvider是要返回的对象
希望有帮助。