How to use failFn method in pact-foundation-pact

Best JavaScript code snippet using pact-foundation-pact

BDWalletJavascript.js

Source:BDWalletJavascript.js Github

copy

Full Screen

1/*2 Copyright 2015 Baidu Inc. All rights reserved.3 File Name: BDWalletJavascript.js4 Author: Baidu5 Data: 2015-1-306 Description: Javascript Library Of Baidu Wallet App7 Modification:8 1. 轻应用注入JS脚本9 */10;(function() {11 var require, define;12 13 (function() {14 var modules = {},15 // Stack of moduleIds currently being built.16 requireStack = [],17 // Map of module ID -> index into requireStack of modules currently being built.18 inProgressModules = {},19 SEPERATOR = ".";20 21 function build(module) {22 var factory = module.factory,23 localRequire = function (id) {24 var resultantId = id;25 //Its a relative path, so lop off the last portion and add the id (minus "./")26 if (id.charAt(0) === ".") {27 resultantId = module.id.slice(0, module.id.lastIndexOf(SEPERATOR)) + SEPERATOR + id.slice(2);28 }29 return require(resultantId);30 };31 32 module.exports = {};33 delete module.factory;34 factory(localRequire, module.exports, module);35 return module.exports;36 }37 38 require = function (id) {39 if (!modules[id]) {40 throw "module " + id + " not found";41 } else if (id in inProgressModules) {42 var cycle = requireStack.slice(inProgressModules[id]).join('->') + '->' + id;43 throw "Cycle in require graph: " + cycle;44 }45 46 if (modules[id].factory) {47 try {48 inProgressModules[id] = requireStack.length;49 requireStack.push(id);50 return build(modules[id]);51 } finally {52 delete inProgressModules[id];53 requireStack.pop();54 }55 }56 57 return modules[id].exports;58 };59 60 define = function (id, factory) {61 if (modules[id]) {62 throw "module " + id + " already defined";63 }64 65 modules[id] = {66 id: id,67 factory: factory68 };69 };70 71 define.remove = function (id) {72 delete modules[id];73 };74 75 define.moduleMap = modules;76 })();77 78 define("bba_la_node", function(require, exports, module) {79 80 var bbaLANode = {81 callbackId: Math.floor(Math.random() * 2000000000),82 callbacks: {},83 commandQueue: [],84 groupId: Math.floor(Math.random() * 300),85 groups: {},86 listeners: {},87 88 invoke: function(cmd, params, onSuccess, onFail, tailParams) {89 if(!cmd) cmd = "defaultCommand";90 if(!params) params = {};91 this.callbackId ++;92 this.callbacks[this.callbackId] = {93 success: onSuccess,94 fail: onFail95 };96 var rurl = "baiduwallet://" + cmd + tailParams + "/" + JSON.stringify(params);97 document.location = rurl;98 },99 callbackSuccess: function(callbackId, params) {100 try {101 bbaLANode.callbackFromNative(callbackId, params, true);102 } catch (e) {103 console.log("Error in error callback: " + callbackId + " = " + e);104 }105 },106 callbackError: function(callbackId, params) {107 try {108 bbaLANode.callbackFromNative(callbackId, params, false);109 } catch (e) {110 console.log("Error in error callback: " + callbackId + " = " + e);111 }112 },113 callbackFromNative: function(callbackId, params, isSuccess) {114 var callback = this.callbacks[callbackId];115 if (callback) {116 if (isSuccess) {117 callback.success && callback.success(callbackId, params);118 } else {119 callback.fail && callback.fail(callbackId, params);120 }121 delete bbaLANode.callbacks[callbackId];122 };123 },124 };125 126 module.exports = bbaLANode;127 });128 129 window.bba_la_node = require("bba_la_node");130 131 }) ();132// ================== Light App Node Invoke ==================133window.BLightApp = window.BLightApp ? window.BLightApp : {};134/* -- 支付端能力 -- */135BLightApp.dopay = function(sucessFn, failFn, orderInfo, hideLoadingDialog, options)136{137 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));138 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));139 options = encodeURIComponent(encodeURIComponent(options || ''));140 orderInfo = orderInfo || '';141 hideLoadingDialog = encodeURIComponent(encodeURIComponent(hideLoadingDialog || ''));142 var params = {'successcallback' : sucessFn, 'hideloadingdialog' : hideLoadingDialog, 'errorcallback' : failFn, 'options' : options};143 var onSuccess = function (callbackId, params) {144 };145 var onFail = function (callbackId, params) {146 };147 148 var scheme = 'dopay?';149 window.bba_la_node.invoke(scheme, params, onSuccess, onFail, orderInfo);150};151/* -- 主动绑卡端能力 -- */152BLightApp.doBindCard = function(sucessFn, failFn, orderInfo, hideLoadingDialog)153{154 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));155 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));156 orderInfo = orderInfo || '';157 hideLoadingDialog = encodeURIComponent(encodeURIComponent(hideLoadingDialog || ''));158 var params = {'successcallback' : sucessFn, 'hideloadingdialog' : hideLoadingDialog, 'errorcallback' : failFn};159 var onSuccess = function (callbackId, params) {160 };161 var onFail = function (callbackId, params) {162 };163 164 var scheme = 'doBindCard?';165 window.bba_la_node.invoke(scheme, params, onSuccess, onFail, orderInfo);166};167/* -- 登录端能力 -- */168BLightApp.bdLogin = function(options, sucessFn, failFn)169{170 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));171 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));172 options = encodeURIComponent(encodeURIComponent(options || ''));173 174 var params = {'successcallback' : sucessFn, 'errorcallback' : failFn, 'options' : options, 'action' : 'lalogindialog'};175 var onSuccess = function (callbackId, params) {176 };177 var onFail = function (callbackId, params) {178 };179 window.bba_la_node.invoke('bdLogin?', params, onSuccess, onFail, '');180};181/* -- 分享端能力 -- */182BLightApp.callShare = function(options, sucessFn, failFn)183{184 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));185 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));186 options = encodeURIComponent(encodeURIComponent(options || ''));187 188 var params = {'successcallback' : sucessFn, 'errorcallback' : failFn, 'options' : options};189 var onSuccess = function (callbackId, params) {190 };191 var onFail = function (callbackId, params) {192 };193 window.bba_la_node.invoke('callShare?', params, onSuccess, onFail, '');194};195/* -- 关闭APP -- */196BLightApp.closeWindow = function()197{198 199 var onSuccess = function (callbackId, params) {200 };201 var onFail = function (callbackId, params) {202 };203 window.bba_la_node.invoke('closeWindow?', '', onSuccess, onFail, '');204};205/* -- 跳转定位设置 -- */206BLightApp.jumpLocationSettings = function(options, sucessFn, failFn)207{208 209 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));210 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));211 options = encodeURIComponent(encodeURIComponent(options || ''));212 var params = {'successcallback' : sucessFn, 'errorcallback' : failFn, 'options' : options};213 var onSuccess = function (callbackId, params) {214 };215 var onFail = function (callbackId, params) {216 };217 window.bba_la_node.invoke('jumpLocationSettings?', '', onSuccess, onFail, '');218};219/* -- 跳转通讯录设置 -- */220BLightApp.jumpAddressBookSettings = function()221{222 223 var onSuccess = function (callbackId, params) {224 };225 var onFail = function (callbackId, params) {226 };227 window.bba_la_node.invoke('jumpAddressBookSettings?', '', onSuccess, onFail, '');228};229/* -- 地理位置能力 -- */230BLightApp.getCurrentPosition = function(options, sucessFn, failFn)231{232 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));233 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));234 options = encodeURIComponent(encodeURIComponent(options || ''));235 236 var params = {'successcallback' : sucessFn, 'errorcallback' : failFn, 'options' : options};237 var onSuccess = function (callbackId, params) {238 };239 var onFail = function (callbackId, params) {240 };241 window.bba_la_node.invoke('getCurrentPosition?', params, onSuccess, onFail, '');242};243/* -- 拍身份证照片能力 -- */244BLightApp.callIDPotos = function(options, sucessFn, failFn)245{246 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));247 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));248 options = encodeURIComponent(encodeURIComponent(options || ''));249 250 var params = {'successcallback' : sucessFn, 'errorcallback' : failFn, 'options' : options};251 var onSuccess = function (callbackId, params) {252 };253 var onFail = function (callbackId, params) {254 };255 window.bba_la_node.invoke('callIDPotos?', params, onSuccess, onFail, '');256};257/* -- 调用系统相机能力 -- */258BLightApp.callCamera = function(options, sucessFn, failFn)259{260 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));261 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));262 options = encodeURIComponent(encodeURIComponent(options || ''));263 264 var params = {'successcallback' : sucessFn, 'errorcallback' : failFn, 'options' : options};265 var onSuccess = function (callbackId, params) {266 };267 var onFail = function (callbackId, params) {268 };269 window.bba_la_node.invoke('callCamera?', params, onSuccess, onFail, '');270};271/* -- 选中通讯录中指定人号码能力 -- */272BLightApp.selectPhonefromAdressBook = function(options, sucessFn, failFn)273{274 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));275 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));276 options = encodeURIComponent(encodeURIComponent(options || ''));277 278 var params = {'successcallback' : sucessFn, 'errorcallback' : failFn, 'options' : options};279 var onSuccess = function (callbackId, params) {280 };281 var onFail = function (callbackId, params) {282 };283 window.bba_la_node.invoke('selectPhonefromAdressBook?', params, onSuccess, onFail, '');284};285/* -- 银行卡识别能力 -- */286BLightApp.detectBankCard = function(options, sucessFn, failFn)287{288 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));289 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));290 options = encodeURIComponent(encodeURIComponent(options || ''));291 292 var params = {'successcallback' : sucessFn, 'errorcallback' : failFn, 'options' : options};293 var onSuccess = function (callbackId, params) {294 };295 var onFail = function (callbackId, params) {296 };297 window.bba_la_node.invoke('detectBankCard?', params, onSuccess, onFail, '');298};299/* -- 获取UA信息 -- */300BLightApp.getUserAgent = function(options, sucessFn, failFn)301{302 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));303 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));304 options = encodeURIComponent(encodeURIComponent(options || ''));305 306 var params = {'successcallback' : sucessFn, 'errorcallback' : failFn, 'options' : options};307 var onSuccess = function (callbackId, params) {308 };309 var onFail = function (callbackId, params) {310 };311 window.bba_la_node.invoke('getUserAgent?', params, onSuccess, onFail, '');312};313/* -- 获取设备信息 -- */314BLightApp.getDeviceInfo = function(options, sucessFn, failFn)315{316 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));317 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));318 options = encodeURIComponent(encodeURIComponent(options || ''));319 320 var params = {'successcallback' : sucessFn, 'errorcallback' : failFn, 'options' : options};321 var onSuccess = function (callbackId, params) {322 };323 var onFail = function (callbackId, params) {324 };325 window.bba_la_node.invoke('getDeviceInfo?', params, onSuccess, onFail, '');326};327/* -- 实名认证 -- */328BLightApp.doRnAuth = function(sucessFn,failFn,options)329{330 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));331 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));332 options = encodeURIComponent(encodeURIComponent(options || ''));333 334 var params = {'successcallback' : sucessFn, 'errorcallback' : failFn, 'options' : options};335 var onSuccess = function (callbackId, params) {336 };337 var onFail = function (callbackId, params) {338 };339 window.bba_la_node.invoke('doRnAuth?', params, onSuccess, onFail, '');340};341/* -- 独立绑卡 -- */342BLightApp.bindCardindependent = function(options,sucessFn,failFn)343{344 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));345 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));346 options = encodeURIComponent(encodeURIComponent(options || ''));347 348 var params = {'successcallback' : sucessFn, 'errorcallback' : failFn, 'options' : options};349 var onSuccess = function (callbackId, params) {350 };351 var onFail = function (callbackId, params) {352 };353 354 window.bba_la_node.invoke('bindCardindependent?', params, onSuccess, onFail, '');355};356/* -- 扫一扫 -- */357BLightApp.callQRCodeScanner = function(options,sucessFn,failFn)358{359 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));360 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));361 options = encodeURIComponent(encodeURIComponent(options || ''));362 363 var params = {'successcallback' : sucessFn, 'errorcallback' : failFn, 'options' : options};364 var onSuccess = function (callbackId, params) {365 };366 var onFail = function (callbackId, params) {367 };368 369 window.bba_la_node.invoke('callQRCodeScanner?', params, onSuccess, onFail, '');370};371/* -- 轻应用统一入口 -- */372BLightApp.invokeBdWalletNative = function(options,sucessFn,failFn)373{374 sucessFn = encodeURIComponent(encodeURIComponent(sucessFn || ''));375 failFn = encodeURIComponent(encodeURIComponent(failFn || ''));376 options = encodeURIComponent(encodeURIComponent(options || ''));377 378 var params = {'successcallback' : sucessFn, 'errorcallback' : failFn, 'options' : options};379 var onSuccess = function (callbackId, params) {380 };381 var onFail = function (callbackId, params) {382 };383 384 window.bba_la_node.invoke('invokeBdWalletNative?', params, onSuccess, onFail, '');385};386/* -- 上报 -- */387BLightApp.doEvent = function(eventName,eventValues)388{389 eventName = encodeURIComponent(encodeURIComponent(eventName || ''));390 eventValues = encodeURIComponent(encodeURIComponent(eventValues || ''));391 392 var params = {'eventName' : eventName, 'eventValues' : eventValues};393 var onSuccess = function (callbackId, params) {394 };395 var onFail = function (callbackId, params) {396 };397 window.bba_la_node.invoke('doEvent?', params, onSuccess, onFail, '');398};399/* -- Runtime注入成功 -- */400function kuangRuntimeReady()401{402 var event = document.createEvent('Events');403 event.initEvent('runtimeready', false,false);404 document.dispatchEvent(event);405}406kuangRuntimeReady();407// Check408function CheckJSLib()409{410 return "ok";411}...

Full Screen

Full Screen

Deferred.js

Source:Deferred.js Github

copy

Full Screen

1define('fir/common/Deferred', [], function(Consts) {2'use strict';3/**4 * Сейчас это обертка на jquery Deferred.5 * Но благодаря ей можно будет легко перейти на Promise при желании6 */7return FirClass(8 function FirDeferred() {9 this._deferred = new $.Deferred();10 }, {11 then: function(doneFn, failFn) {12 if( (doneFn != null) && (failFn == null) && (typeof doneFn !== 'function') ) {13 // Probably Deferred passed14 this._deferred.then(doneFn);15 return;16 }17 if( (doneFn != null) && (typeof doneFn !== 'function') ) {18 throw new Error('doneFn argument expected to be function, undefined or null');19 }20 if( (failFn != null) && (typeof failFn !== 'function') ) {21 throw new Error('failFn argument expected to be function, undefined or null');22 }23 this._deferred.then(doneFn, failFn);24 },25 catch: function(failFn) {26 if( (failFn != null) && (typeof failFn !== 'function') ) {27 throw new Error('failFn argument expected to be function, undefined or null');28 }29 this._deferred.catch(failFn);30 },31 resolve: function() {32 this._deferred.resolve.apply(this._deferred, Array.prototype.slice.call(arguments));33 },34 reject: function() {35 this._deferred.reject.apply(this._deferred, Array.prototype.slice.call(arguments));36 }37 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Verifier } = require('@pact-foundation/pact');2const path = require('path');3const opts = {4 pactUrls: [path.resolve(process.cwd(), 'pacts', 'test1-test2.json')],5 consumerVersionSelectors: [{6 }],7 providerVersionSelectors: [{8 }]9};10new Verifier(opts).verifyProvider()11 .then(output => {12 console.log('Pact Verification Complete!')13 console.log(output)14 })15 .catch(e => {16 console.log('Pact Verification Failed: ', e)17 })18const { Verifier } = require('@pact-foundation/pact');19const path = require('path');20const opts = {21 pactUrls: [path.resolve(process.cwd(), 'pacts', 'test1-test2.json')],22 consumerVersionSelectors: [{23 }],24 providerVersionSelectors: [{25 }]26};27new Verifier(opts).verifyProvider()28 .then(output => {29 console.log('Pact Verification Complete!')30 console.log(output)31 })32 .catch(e => {33 console.log('Pact Verification Failed: ', e)34 })35const { Verifier } = require('@pact-foundation/pact');36const path = require('path');37const opts = {38 pactUrls: [path.resolve(process.cwd(), 'pacts', 'test1-test2.json')],

Full Screen

Using AI Code Generation

copy

Full Screen

1var pact = require('pact-foundation-pact');2var path = require('path');3var opts = {4 log: path.resolve(process.cwd(), 'logs', 'pact.log'),5 dir: path.resolve(process.cwd(), 'pacts'),6};7var provider = pact(opts);8provider.setup()9 .then(function () {10 provider.addInteraction({11 withRequest: {12 headers: {13 }14 },15 willRespondWith: {16 headers: {17 "Content-Type": "application/json; charset=utf-8"18 },19 body: [{20 }]21 }22 })23 .then(function () {24 console.log("test2.js: provider.addInteraction completed");25 provider.verify();26 })27 .then(function () {28 console.log("test2.js: provider.verify completed");29 provider.finalize();30 })31 .then(function () {32 console.log("test2.js: provider.finalize completed");33 });34})35 .catch(function (err) {36 console.log("test2.js: provider.setup failed: " + err);37});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Matchers } = require('@pact-foundation/pact');2const { somethingLike } = Matchers;3const getPlanets = async (url) => {4 const res = await fetch(url);5 return res.json();6};7const getPlanetsWithFailFn = async (url) => {8 const res = await fetch(url);9 if (res.status >= 400) {10 throw new Error('Error');11 }12 return res.json();13};14describe('Planet API', () => {15 describe('when a request to list all the planets is made', () => {16 beforeAll(async () => {17 const interaction = {18 withRequest: {19 headers: {20 },21 },22 willRespondWith: {23 headers: {24 'Content-Type': 'application/json;charset=utf-8',25 },26 {27 id: somethingLike(1),28 name: somethingLike('Tatooine'),29 climate: somethingLike('arid'),30 terrain: somethingLike('desert'),31 films: somethingLike(5),32 },33 },34 };35 await provider.addInteraction(interaction);36 });37 test('returns a successful body', async () => {38 const body = await getPlanets(`${url}/planets`);39 expect(body).toEqual([40 {41 },42 ]);43 });44 });45 describe('when a request to list all the planets is made and failFn is used', () => {46 beforeAll(async () => {47 const interaction = {48 withRequest: {49 headers: {50 },51 },52 willRespondWith: {53 headers: {

Full Screen

Using AI Code Generation

copy

Full Screen

1pact.verify().then(function () {2 console.log("Pact Verification Complete!")3 console.log("Pact File Written!")4}, function (err) {5 console.log("Pact Verification Failed: ", err)6})

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pact-foundation-pact automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful