How to use argument method in wpt

Best JavaScript code snippet using wpt

mockmatchers.js

Source:mockmatchers.js Github

copy

Full Screen

1// Copyright 2008 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14/**15 * @fileoverview Matchers to be used with the mock utilities. They allow for16 * flexible matching by type. Custom matchers can be created by passing a17 * matcher function into an ArgumentMatcher instance.18 *19 * For examples, please see the unit test.20 *21 */22goog.provide('goog.testing.mockmatchers');23goog.provide('goog.testing.mockmatchers.ArgumentMatcher');24goog.provide('goog.testing.mockmatchers.IgnoreArgument');25goog.provide('goog.testing.mockmatchers.InstanceOf');26goog.provide('goog.testing.mockmatchers.ObjectEquals');27goog.provide('goog.testing.mockmatchers.RegexpMatch');28goog.provide('goog.testing.mockmatchers.SaveArgument');29goog.provide('goog.testing.mockmatchers.TypeOf');30goog.require('goog.array');31goog.require('goog.dom');32goog.require('goog.testing.asserts');33/**34 * A simple interface for executing argument matching. A match in this case is35 * testing to see if a supplied object fits a given criteria. True is returned36 * if the given criteria is met.37 * @param {Function=} opt_matchFn A function that evaluates a given argument38 * and returns true if it meets a given criteria.39 * @param {?string=} opt_matchName The name expressing intent as part of40 * an error message for when a match fails.41 * @constructor42 */43goog.testing.mockmatchers.ArgumentMatcher =44 function(opt_matchFn, opt_matchName) {45 /**46 * A function that evaluates a given argument and returns true if it meets a47 * given criteria.48 * @type {Function}49 * @private50 */51 this.matchFn_ = opt_matchFn || null;52 /**53 * A string indicating the match intent (e.g. isBoolean or isString).54 * @type {?string}55 * @private56 */57 this.matchName_ = opt_matchName || null;58};59/**60 * A function that takes a match argument and an optional MockExpectation61 * which (if provided) will get error information and returns whether or62 * not it matches.63 * @param {*} toVerify The argument that should be verified.64 * @param {goog.testing.MockExpectation?=} opt_expectation The expectation65 * for this match.66 * @return {boolean} Whether or not a given argument passes verification.67 */68goog.testing.mockmatchers.ArgumentMatcher.prototype.matches =69 function(toVerify, opt_expectation) {70 if (this.matchFn_) {71 var isamatch = this.matchFn_(toVerify);72 if (!isamatch && opt_expectation) {73 if (this.matchName_) {74 opt_expectation.addErrorMessage('Expected: ' +75 this.matchName_ + ' but was: ' + _displayStringForValue(toVerify));76 } else {77 opt_expectation.addErrorMessage('Expected: missing mockmatcher' +78 ' description but was: ' +79 _displayStringForValue(toVerify));80 }81 }82 return isamatch;83 } else {84 throw Error('No match function defined for this mock matcher');85 }86};87/**88 * A matcher that verifies that an argument is an instance of a given class.89 * @param {Function} ctor The class that will be used for verification.90 * @constructor91 * @extends {goog.testing.mockmatchers.ArgumentMatcher}92 */93goog.testing.mockmatchers.InstanceOf = function(ctor) {94 goog.testing.mockmatchers.ArgumentMatcher.call(this,95 function(obj) {96 return obj instanceof ctor;97 // NOTE: Browser differences on ctor.toString() output98 // make using that here problematic. So for now, just let99 // people know the instanceOf() failed without providing100 // browser specific details...101 }, 'instanceOf()');102};103goog.inherits(goog.testing.mockmatchers.InstanceOf,104 goog.testing.mockmatchers.ArgumentMatcher);105/**106 * A matcher that verifies that an argument is of a given type (e.g. "object").107 * @param {string} type The type that a given argument must have.108 * @constructor109 * @extends {goog.testing.mockmatchers.ArgumentMatcher}110 */111goog.testing.mockmatchers.TypeOf = function(type) {112 goog.testing.mockmatchers.ArgumentMatcher.call(this,113 function(obj) {114 return goog.typeOf(obj) == type;115 }, 'typeOf(' + type + ')');116};117goog.inherits(goog.testing.mockmatchers.TypeOf,118 goog.testing.mockmatchers.ArgumentMatcher);119/**120 * A matcher that verifies that an argument matches a given RegExp.121 * @param {RegExp} regexp The regular expression that the argument must match.122 * @constructor123 * @extends {goog.testing.mockmatchers.ArgumentMatcher}124 */125goog.testing.mockmatchers.RegexpMatch = function(regexp) {126 goog.testing.mockmatchers.ArgumentMatcher.call(this,127 function(str) {128 return regexp.test(str);129 }, 'match(' + regexp + ')');130};131goog.inherits(goog.testing.mockmatchers.RegexpMatch,132 goog.testing.mockmatchers.ArgumentMatcher);133/**134 * A matcher that always returns true. It is useful when the user does not care135 * for some arguments.136 * For example: mockFunction('username', 'password', IgnoreArgument);137 * @constructor138 * @extends {goog.testing.mockmatchers.ArgumentMatcher}139 */140goog.testing.mockmatchers.IgnoreArgument = function() {141 goog.testing.mockmatchers.ArgumentMatcher.call(this,142 function() {143 return true;144 }, 'true');145};146goog.inherits(goog.testing.mockmatchers.IgnoreArgument,147 goog.testing.mockmatchers.ArgumentMatcher);148/**149 * A matcher that verifies that the argument is an object that equals the given150 * expected object, using a deep comparison.151 * @param {Object} expectedObject An object to match against when152 * verifying the argument.153 * @constructor154 * @extends {goog.testing.mockmatchers.ArgumentMatcher}155 */156goog.testing.mockmatchers.ObjectEquals = function(expectedObject) {157 goog.testing.mockmatchers.ArgumentMatcher.call(this,158 function(matchObject) {159 assertObjectEquals('Expected equal objects', expectedObject,160 matchObject);161 return true;162 }, 'objectEquals(' + expectedObject + ')');163};164goog.inherits(goog.testing.mockmatchers.ObjectEquals,165 goog.testing.mockmatchers.ArgumentMatcher);166/** @override */167goog.testing.mockmatchers.ObjectEquals.prototype.matches =168 function(toVerify, opt_expectation) {169 // Override the default matches implementation to capture the exception thrown170 // by assertObjectEquals (if any) and add that message to the expectation.171 try {172 return goog.testing.mockmatchers.ObjectEquals.superClass_.matches.call(173 this, toVerify, opt_expectation);174 } catch (e) {175 if (opt_expectation) {176 opt_expectation.addErrorMessage(e.message);177 }178 return false;179 }180};181/**182 * A matcher that saves the argument that it is verifying so that your unit test183 * can perform extra tests with this argument later. For example, if the184 * argument is a callback method, the unit test can then later call this185 * callback to test the asynchronous portion of the call.186 * @param {goog.testing.mockmatchers.ArgumentMatcher|Function=} opt_matcher187 * Argument matcher or matching function that will be used to validate the188 * argument. By default, argument will always be valid.189 * @param {?string=} opt_matchName The name expressing intent as part of190 * an error message for when a match fails.191 * @constructor192 * @extends {goog.testing.mockmatchers.ArgumentMatcher}193 */194goog.testing.mockmatchers.SaveArgument = function(opt_matcher, opt_matchName) {195 goog.testing.mockmatchers.ArgumentMatcher.call(196 this, /** @type {Function} */ (opt_matcher), opt_matchName);197 if (opt_matcher instanceof goog.testing.mockmatchers.ArgumentMatcher) {198 /**199 * Delegate match requests to this matcher.200 * @type {goog.testing.mockmatchers.ArgumentMatcher}201 * @private202 */203 this.delegateMatcher_ = opt_matcher;204 } else if (!opt_matcher) {205 this.delegateMatcher_ = goog.testing.mockmatchers.ignoreArgument;206 }207};208goog.inherits(goog.testing.mockmatchers.SaveArgument,209 goog.testing.mockmatchers.ArgumentMatcher);210/** @override */211goog.testing.mockmatchers.SaveArgument.prototype.matches = function(212 toVerify, opt_expectation) {213 this.arg = toVerify;214 if (this.delegateMatcher_) {215 return this.delegateMatcher_.matches(toVerify, opt_expectation);216 }217 return goog.testing.mockmatchers.SaveArgument.superClass_.matches.call(218 this, toVerify, opt_expectation);219};220/**221 * Saved argument that was verified.222 * @type {*}223 */224goog.testing.mockmatchers.SaveArgument.prototype.arg;225/**226 * An instance of the IgnoreArgument matcher. Returns true for all matches.227 * @type {goog.testing.mockmatchers.IgnoreArgument}228 */229goog.testing.mockmatchers.ignoreArgument =230 new goog.testing.mockmatchers.IgnoreArgument();231/**232 * A matcher that verifies that an argument is an array.233 * @type {goog.testing.mockmatchers.ArgumentMatcher}234 */235goog.testing.mockmatchers.isArray =236 new goog.testing.mockmatchers.ArgumentMatcher(goog.isArray,237 'isArray');238/**239 * A matcher that verifies that an argument is a array-like. A NodeList is an240 * example of a collection that is very close to an array.241 * @type {goog.testing.mockmatchers.ArgumentMatcher}242 */243goog.testing.mockmatchers.isArrayLike =244 new goog.testing.mockmatchers.ArgumentMatcher(goog.isArrayLike,245 'isArrayLike');246/**247 * A matcher that verifies that an argument is a date-like.248 * @type {goog.testing.mockmatchers.ArgumentMatcher}249 */250goog.testing.mockmatchers.isDateLike =251 new goog.testing.mockmatchers.ArgumentMatcher(goog.isDateLike,252 'isDateLike');253/**254 * A matcher that verifies that an argument is a string.255 * @type {goog.testing.mockmatchers.ArgumentMatcher}256 */257goog.testing.mockmatchers.isString =258 new goog.testing.mockmatchers.ArgumentMatcher(goog.isString,259 'isString');260/**261 * A matcher that verifies that an argument is a boolean.262 * @type {goog.testing.mockmatchers.ArgumentMatcher}263 */264goog.testing.mockmatchers.isBoolean =265 new goog.testing.mockmatchers.ArgumentMatcher(goog.isBoolean,266 'isBoolean');267/**268 * A matcher that verifies that an argument is a number.269 * @type {goog.testing.mockmatchers.ArgumentMatcher}270 */271goog.testing.mockmatchers.isNumber =272 new goog.testing.mockmatchers.ArgumentMatcher(goog.isNumber,273 'isNumber');274/**275 * A matcher that verifies that an argument is a function.276 * @type {goog.testing.mockmatchers.ArgumentMatcher}277 */278goog.testing.mockmatchers.isFunction =279 new goog.testing.mockmatchers.ArgumentMatcher(goog.isFunction,280 'isFunction');281/**282 * A matcher that verifies that an argument is an object.283 * @type {goog.testing.mockmatchers.ArgumentMatcher}284 */285goog.testing.mockmatchers.isObject =286 new goog.testing.mockmatchers.ArgumentMatcher(goog.isObject,287 'isObject');288/**289 * A matcher that verifies that an argument is like a DOM node.290 * @type {goog.testing.mockmatchers.ArgumentMatcher}291 */292goog.testing.mockmatchers.isNodeLike =293 new goog.testing.mockmatchers.ArgumentMatcher(goog.dom.isNodeLike,294 'isNodeLike');295/**296 * A function that checks to see if an array matches a given set of297 * expectations. The expectations array can be a mix of ArgumentMatcher298 * implementations and values. True will be returned if values are identical or299 * if a matcher returns a positive result.300 * @param {Array} expectedArr An array of expectations which can be either301 * values to check for equality or ArgumentMatchers.302 * @param {Array} arr The array to match.303 * @param {goog.testing.MockExpectation?=} opt_expectation The expectation304 * for this match.305 * @return {boolean} Whether or not the given array matches the expectations.306 */307goog.testing.mockmatchers.flexibleArrayMatcher =308 function(expectedArr, arr, opt_expectation) {309 return goog.array.equals(expectedArr, arr, function(a, b) {310 var errCount = 0;311 if (opt_expectation) {312 errCount = opt_expectation.getErrorMessageCount();313 }314 var isamatch = a === b ||315 a instanceof goog.testing.mockmatchers.ArgumentMatcher &&316 a.matches(b, opt_expectation);317 var failureMessage = null;318 if (!isamatch) {319 failureMessage = goog.testing.asserts.findDifferences(a, b);320 isamatch = !failureMessage;321 }322 if (!isamatch && opt_expectation) {323 // If the error count changed, the match sent out an error324 // message. If the error count has not changed, then325 // we need to send out an error message...326 if (errCount == opt_expectation.getErrorMessageCount()) {327 // Use the _displayStringForValue() from assert.js328 // for consistency...329 if (!failureMessage) {330 failureMessage = 'Expected: ' + _displayStringForValue(a) +331 ' but was: ' + _displayStringForValue(b);332 }333 opt_expectation.addErrorMessage(failureMessage);334 }335 }336 return isamatch;337 });...

Full Screen

Full Screen

universal-argument.js

Source:universal-argument.js Github

copy

Full Screen

1/**2 * (C) Copyright 2004-2007 Shawn Betts3 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard4 * (C) Copyright 2008 John Foerch5 *6 * Use, modification, and distribution are subject to the terms specified in the7 * COPYING file.8**/9define_keymap("universal_argument_keymap");10interactive("universal-argument",11 "Begin a numeric argument for the following command.",12 function (I) {13 if (I.prefix_argument) {14 if (typeof I.prefix_argument == "object") // must be array15 I.prefix_argument = [I.prefix_argument[0] * 4];16 } else17 I.prefix_argument = [4];18 I.overlay_keymap = universal_argument_keymap;19 },20 $prefix = true);21interactive("universal-digit",22 "Part of the numeric argument for the next command.",23 function (I) {24 var digit = I.event.charCode - 48;25 if (I.prefix_argument == null)26 I.prefix_argument = digit;27 else if (typeof I.prefix_argument == "object") { // array28 if (I.prefix_argument[0] < 0)29 I.prefix_argument = -digit;30 else31 I.prefix_argument = digit;32 }33 else if (I.prefix_argument < 0)34 I.prefix_argument = I.prefix_argument * 10 - digit;35 else36 I.prefix_argument = I.prefix_argument * 10 + digit;37 },38 $prefix = true);39interactive("universal-negate",40 "Part of the numeric argument for the next command. "+41 "This command negates the numeric argument.",42 function universal_negate (I) {43 if (typeof I.prefix_argument == "object")44 I.prefix_argument[0] = 0 - I.prefix_argument[0];45 else46 I.prefix_argument = 0 - I.prefix_argument;47 },48 $prefix = true);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org','A.1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6');3 if (err) return console.error(err);4 console.log(data);5});6var wpt = require('webpagetest');7var test = new wpt('www.webpagetest.org','A.1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6');8 if (err) return console.error(err);9 console.log(data);10});11var wpt = require('webpagetest');12var test = new wpt('www.webpagetest.org','A.1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6');13 if (err) return console.error(err);14 console.log(data);15});16var wpt = require('webpagetest');17var test = new wpt('www.webpagetest.org','A.1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6');18 if (err) return console.error(err);19 console.log(data);20});21var wpt = require('webpagetest');22var test = new wpt('www.webpagetest.org

Full Screen

Using AI Code Generation

copy

Full Screen

1}, function(err, data) {2 console.log(data);3});4}, function(err, data) {5 console.log(data);6});7}, function(err, data) {8 console.log(data);9});10}).then(function(data) {11 console.log(data);12}).catch(function(err) {13 console.log(err);14});15}).then(function(data) {16 console.log(data);17}).catch(function(err) {18 console.log(err);19});20}).then(function(data) {21 console.log(data);22}).catch(function(err) {23 console.log(err);24});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 console.log(data);4});5wpt.runTest('index.html', { location: 'localhost', connectivity: 'Cable', runs: 3 }, function(err, data) {6 console.log(data);7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org');3var options = {4};5test.runTest(url, options, function(err, data) {6 if (err) return console.error(err);7 console.log(data);8});9var wpt = require('webpagetest');10var test = new wpt('www.webpagetest.org');11var options = {12};13test.runTest(url, options, function(err, data) {14 if (err) return console.error(err);15 console.log(data);16});17var wpt = require('webpagetest');18var test = new wpt('www.webpagetest.org

Full Screen

Using AI Code Generation

copy

Full Screen

1var args = wpt.getArgs();2console.log(args["arg1"]);3console.log(args["arg2"]);4var args = wpt.getArgs();5console.log(args["arg1"]);6console.log(args["arg2"]);7var args = wpt.getArgs();8console.log(args["arg1"]);9console.log(args["arg2"]);10var args = wpt.getArgs();11console.log(args["arg1"]);12console.log(args["arg2"]);13var args = wpt.getArgs();14console.log(args["arg1"]);15console.log(args["arg2"]);16var args = wpt.getArgs();

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 wpt 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