【发布时间】:2019-08-26 13:01:31
【问题描述】:
我想在 Jest 中模拟节点 Stripe SDK,因为我不想从 Stripe 运行模拟 API 服务器,但我不知道该怎么做。我正在创建一个__mocks__ 目录并添加stripe.js,但我无法获得任何可用于导出的内容。
我通常在拨打strypegw.charges.create() 时收到TypeError: Cannot read property 'create' of undefined。我使用的是 ES6 模块语法,所以我 import stripe from 'stripe'.
【问题讨论】:
-
你到底在尝试什么?
-
您还必须在 Stripe-Node 中模拟
resources。要么手动添加stripe.js中的所有资源,要么根据github.com/stripe/stripe-node/blob/master/lib/stripe.js#L342模拟它们 -
您可以使用like this 服务,您可以轻松地从测试中进行 HTTP 调用。可能比模拟更简单。
标签: node.js jestjs stripe-payments