42-cent-mock 中文文档教程

发布于 10年前 浏览 26 项目主页 更新于 3年前

42-cent-mock

用于测试的抽象 42 美分支付网关的模拟实现

usage

  • register the mock factory in place of whatever gateway, the factory will return a singleton instance of the mocked gateway
var cent42=require('42-cent');
var gm=require('42-cent-mock');

cent42.registerGateway('Authorize.net',gm.factory);
  • stub call and make assertions on arguments
var stub = gm.when('refundTransaction').resolveWith({status:'success'});

gm.factory().refundTransaction('666',{amount:123});

assert.equal(stub.calls.length,1);
assert.equal(stub.calls[0][0], '666')
assert.equal(stub.calls[0][1].amount,123);
  • clean the currently set stubs (tear down phase of your test)
gm.clean();

42-cent-mock

mock implementation of abstract 42-cent payement gateway to use for tests

usage

  • register the mock factory in place of whatever gateway, the factory will return a singleton instance of the mocked gateway
var cent42=require('42-cent');
var gm=require('42-cent-mock');

cent42.registerGateway('Authorize.net',gm.factory);
  • stub call and make assertions on arguments
var stub = gm.when('refundTransaction').resolveWith({status:'success'});

gm.factory().refundTransaction('666',{amount:123});

assert.equal(stub.calls.length,1);
assert.equal(stub.calls[0][0], '666')
assert.equal(stub.calls[0][1].amount,123);
  • clean the currently set stubs (tear down phase of your test)
gm.clean();
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文