How to use createChainableTypeChecker method in Playwright Internal

Best JavaScript code snippet using playwright-internal

factoryWithTypeCheckers.js

Source:factoryWithTypeCheckers.js Github

copy

Full Screen

...152 this.stack = '';153 }154 // Make `instanceof Error` still work for returned errors.155 PropTypeError.prototype = Error.prototype;156 function createChainableTypeChecker(validate) {157 if (process.env.NODE_ENV !== 'production') {158 var manualPropTypeCallCache = {};159 var manualPropTypeWarningCount = 0;160 }161 function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {162 componentName = componentName || ANONYMOUS;163 propFullName = propFullName || propName;164 if (secret !== ReactPropTypesSecret) {165 if (throwOnDirectAccess) {166 // New behavior only for users of `prop-types` package167 var err = new Error(168 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +169 'Use `PropTypes.checkPropTypes()` to call them. ' +170 'Read more at http://fb.me/use-check-prop-types'171 );172 err.name = 'Invariant Violation';173 throw err;174 } else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') {175 // Old behavior for people using React.PropTypes176 var cacheKey = componentName + ':' + propName;177 if (178 !manualPropTypeCallCache[cacheKey] &&179 // Avoid spamming the console because they are often not actionable except for lib authors180 manualPropTypeWarningCount < 3181 ) {182 printWarning(183 'You are manually calling a React.PropTypes validation ' +184 'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +185 'and will throw in the standalone `prop-types` package. ' +186 'You may be seeing this warning due to a third-party PropTypes ' +187 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'188 );189 manualPropTypeCallCache[cacheKey] = true;190 manualPropTypeWarningCount++;191 }192 }193 }194 if (props[propName] == null) {195 if (isRequired) {196 if (props[propName] === null) {197 return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));198 }199 return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));200 }201 return null;202 } else {203 return validate(props, propName, componentName, location, propFullName);204 }205 }206 var chainedCheckType = checkType.bind(null, false);207 chainedCheckType.isRequired = checkType.bind(null, true);208 return chainedCheckType;209 }210 function createPrimitiveTypeChecker(expectedType) {211 function validate(props, propName, componentName, location, propFullName, secret) {212 var propValue = props[propName];213 var propType = getPropType(propValue);214 if (propType !== expectedType) {215 // `propValue` being instance of, say, date/regexp, pass the 'object'216 // check, but we can offer a more precise error message here rather than217 // 'of type `object`'.218 var preciseType = getPreciseType(propValue);219 return new PropTypeError(220 'Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'),221 {expectedType: expectedType}222 );223 }224 return null;225 }226 return createChainableTypeChecker(validate);227 }228 function createAnyTypeChecker() {229 return createChainableTypeChecker(emptyFunctionThatReturnsNull);230 }231 function createArrayOfTypeChecker(typeChecker) {232 function validate(props, propName, componentName, location, propFullName) {233 if (typeof typeChecker !== 'function') {234 return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');235 }236 var propValue = props[propName];237 if (!Array.isArray(propValue)) {238 var propType = getPropType(propValue);239 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));240 }241 for (var i = 0; i < propValue.length; i++) {242 var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);243 if (error instanceof Error) {244 return error;245 }246 }247 return null;248 }249 return createChainableTypeChecker(validate);250 }251 function createElementTypeChecker() {252 function validate(props, propName, componentName, location, propFullName) {253 var propValue = props[propName];254 if (!isValidElement(propValue)) {255 var propType = getPropType(propValue);256 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));257 }258 return null;259 }260 return createChainableTypeChecker(validate);261 }262 function createElementTypeTypeChecker() {263 function validate(props, propName, componentName, location, propFullName) {264 var propValue = props[propName];265 if (!ReactIs.isValidElementType(propValue)) {266 var propType = getPropType(propValue);267 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.'));268 }269 return null;270 }271 return createChainableTypeChecker(validate);272 }273 function createInstanceTypeChecker(expectedClass) {274 function validate(props, propName, componentName, location, propFullName) {275 if (!(props[propName] instanceof expectedClass)) {276 var expectedClassName = expectedClass.name || ANONYMOUS;277 var actualClassName = getClassName(props[propName]);278 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));279 }280 return null;281 }282 return createChainableTypeChecker(validate);283 }284 function createEnumTypeChecker(expectedValues) {285 if (!Array.isArray(expectedValues)) {286 if (process.env.NODE_ENV !== 'production') {287 if (arguments.length > 1) {288 printWarning(289 'Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' +290 'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).'291 );292 } else {293 printWarning('Invalid argument supplied to oneOf, expected an array.');294 }295 }296 return emptyFunctionThatReturnsNull;297 }298 function validate(props, propName, componentName, location, propFullName) {299 var propValue = props[propName];300 for (var i = 0; i < expectedValues.length; i++) {301 if (is(propValue, expectedValues[i])) {302 return null;303 }304 }305 var valuesString = JSON.stringify(expectedValues, function replacer(key, value) {306 var type = getPreciseType(value);307 if (type === 'symbol') {308 return String(value);309 }310 return value;311 });312 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));313 }314 return createChainableTypeChecker(validate);315 }316 function createObjectOfTypeChecker(typeChecker) {317 function validate(props, propName, componentName, location, propFullName) {318 if (typeof typeChecker !== 'function') {319 return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');320 }321 var propValue = props[propName];322 var propType = getPropType(propValue);323 if (propType !== 'object') {324 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));325 }326 for (var key in propValue) {327 if (has(propValue, key)) {328 var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);329 if (error instanceof Error) {330 return error;331 }332 }333 }334 return null;335 }336 return createChainableTypeChecker(validate);337 }338 function createUnionTypeChecker(arrayOfTypeCheckers) {339 if (!Array.isArray(arrayOfTypeCheckers)) {340 process.env.NODE_ENV !== 'production' ? printWarning('Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;341 return emptyFunctionThatReturnsNull;342 }343 for (var i = 0; i < arrayOfTypeCheckers.length; i++) {344 var checker = arrayOfTypeCheckers[i];345 if (typeof checker !== 'function') {346 printWarning(347 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +348 'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.'349 );350 return emptyFunctionThatReturnsNull;351 }352 }353 function validate(props, propName, componentName, location, propFullName) {354 var expectedTypes = [];355 for (var i = 0; i < arrayOfTypeCheckers.length; i++) {356 var checker = arrayOfTypeCheckers[i];357 var checkerResult = checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret);358 if (checkerResult == null) {359 return null;360 }361 if (checkerResult.data && has(checkerResult.data, 'expectedType')) {362 expectedTypes.push(checkerResult.data.expectedType);363 }364 }365 var expectedTypesMessage = (expectedTypes.length > 0) ? ', expected one of type [' + expectedTypes.join(', ') + ']': '';366 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`' + expectedTypesMessage + '.'));367 }368 return createChainableTypeChecker(validate);369 }370 function createNodeChecker() {371 function validate(props, propName, componentName, location, propFullName) {372 if (!isNode(props[propName])) {373 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));374 }375 return null;376 }377 return createChainableTypeChecker(validate);378 }379 function invalidValidatorError(componentName, location, propFullName, key, type) {380 return new PropTypeError(381 (componentName || 'React class') + ': ' + location + ' type `' + propFullName + '.' + key + '` is invalid; ' +382 'it must be a function, usually from the `prop-types` package, but received `' + type + '`.'383 );384 }385 function createShapeTypeChecker(shapeTypes) {386 function validate(props, propName, componentName, location, propFullName) {387 var propValue = props[propName];388 var propType = getPropType(propValue);389 if (propType !== 'object') {390 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));391 }392 for (var key in shapeTypes) {393 var checker = shapeTypes[key];394 if (typeof checker !== 'function') {395 return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));396 }397 var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);398 if (error) {399 return error;400 }401 }402 return null;403 }404 return createChainableTypeChecker(validate);405 }406 function createStrictShapeTypeChecker(shapeTypes) {407 function validate(props, propName, componentName, location, propFullName) {408 var propValue = props[propName];409 var propType = getPropType(propValue);410 if (propType !== 'object') {411 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));412 }413 // We need to check all keys in case some are required but missing from props.414 var allKeys = assign({}, props[propName], shapeTypes);415 for (var key in allKeys) {416 var checker = shapeTypes[key];417 if (has(shapeTypes, key) && typeof checker !== 'function') {418 return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));419 }420 if (!checker) {421 return new PropTypeError(422 'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +423 '\nBad object: ' + JSON.stringify(props[propName], null, ' ') +424 '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')425 );426 }427 var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);428 if (error) {429 return error;430 }431 }432 return null;433 }434 return createChainableTypeChecker(validate);435 }436 function isNode(propValue) {437 switch (typeof propValue) {438 case 'number':439 case 'string':440 case 'undefined':441 return true;442 case 'boolean':443 return !propValue;444 case 'object':445 if (Array.isArray(propValue)) {446 return propValue.every(isNode);447 }448 if (propValue === null || isValidElement(propValue)) {...

Full Screen

Full Screen

ReactPropTypes.js

Source:ReactPropTypes.js Github

copy

Full Screen

...21 oneOf: createEnumTypeChecker,22 oneOfType: createUnionTypeChecker,23 shape: createShapeTypeChecker24};25function createChainableTypeChecker(validate) {26 function checkType(isRequired, props, propName, componentName, location, propFullName) {27 componentName = componentName || ANONYMOUS;28 propFullName = propFullName || propName;29 if (props[propName] == null) {30 var locationName = ReactPropTypeLocationNames[location];31 if (isRequired) {32 return new Error('Required ' + locationName + ' `' + propFullName + '` was not specified in ' + ('`' + componentName + '`.'));33 }34 return null;35 } else {36 return validate(props, propName, componentName, location, propFullName);37 }38 }39 var chainedCheckType = checkType.bind(null, false);40 chainedCheckType.isRequired = checkType.bind(null, true);41 return chainedCheckType;42}43function createPrimitiveTypeChecker(expectedType) {44 function validate(props, propName, componentName, location, propFullName) {45 var propValue = props[propName];46 var propType = getPropType(propValue);47 if (propType !== expectedType) {48 var locationName = ReactPropTypeLocationNames[location];49 var preciseType = getPreciseType(propValue);50 return new Error('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));51 }52 return null;53 }54 return createChainableTypeChecker(validate);55}56function createAnyTypeChecker() {57 return createChainableTypeChecker(emptyFunction.thatReturns(null));58}59function createArrayOfTypeChecker(typeChecker) {60 function validate(props, propName, componentName, location, propFullName) {61 var propValue = props[propName];62 if (!Array.isArray(propValue)) {63 var locationName = ReactPropTypeLocationNames[location];64 var propType = getPropType(propValue);65 return new Error('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));66 }67 for (var i = 0; i < propValue.length; i++) {68 var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']');69 if (error instanceof Error) {70 return error;71 }72 }73 return null;74 }75 return createChainableTypeChecker(validate);76}77function createElementTypeChecker() {78 function validate(props, propName, componentName, location, propFullName) {79 if (!ReactElement.isValidElement(props[propName])) {80 var locationName = ReactPropTypeLocationNames[location];81 return new Error('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a single ReactElement.'));82 }83 return null;84 }85 return createChainableTypeChecker(validate);86}87function createInstanceTypeChecker(expectedClass) {88 function validate(props, propName, componentName, location, propFullName) {89 if (!(props[propName] instanceof expectedClass)) {90 var locationName = ReactPropTypeLocationNames[location];91 var expectedClassName = expectedClass.name || ANONYMOUS;92 var actualClassName = getClassName(props[propName]);93 return new Error('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));94 }95 return null;96 }97 return createChainableTypeChecker(validate);98}99function createEnumTypeChecker(expectedValues) {100 if (!Array.isArray(expectedValues)) {101 return createChainableTypeChecker(function() {102 return new Error('Invalid argument supplied to oneOf, expected an instance of array.');103 });104 }105 function validate(props, propName, componentName, location, propFullName) {106 var propValue = props[propName];107 for (var i = 0; i < expectedValues.length; i++) {108 if (propValue === expectedValues[i]) {109 return null;110 }111 }112 var locationName = ReactPropTypeLocationNames[location];113 var valuesString = JSON.stringify(expectedValues);114 return new Error('Invalid ' + locationName + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));115 }116 return createChainableTypeChecker(validate);117}118function createObjectOfTypeChecker(typeChecker) {119 function validate(props, propName, componentName, location, propFullName) {120 var propValue = props[propName];121 var propType = getPropType(propValue);122 if (propType !== 'object') {123 var locationName = ReactPropTypeLocationNames[location];124 return new Error('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));125 }126 for (var key in propValue) {127 if (propValue.hasOwnProperty(key)) {128 var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key);129 if (error instanceof Error) {130 return error;131 }132 }133 }134 return null;135 }136 return createChainableTypeChecker(validate);137}138function createUnionTypeChecker(arrayOfTypeCheckers) {139 if (!Array.isArray(arrayOfTypeCheckers)) {140 return createChainableTypeChecker(function() {141 return new Error('Invalid argument supplied to oneOfType, expected an instance of array.');142 });143 }144 function validate(props, propName, componentName, location, propFullName) {145 for (var i = 0; i < arrayOfTypeCheckers.length; i++) {146 var checker = arrayOfTypeCheckers[i];147 if (checker(props, propName, componentName, location, propFullName) == null) {148 return null;149 }150 }151 var locationName = ReactPropTypeLocationNames[location];152 return new Error('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));153 }154 return createChainableTypeChecker(validate);155}156function createNodeChecker() {157 function validate(props, propName, componentName, location, propFullName) {158 if (!isNode(props[propName])) {159 var locationName = ReactPropTypeLocationNames[location];160 return new Error('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));161 }162 return null;163 }164 return createChainableTypeChecker(validate);165}166function createShapeTypeChecker(shapeTypes) {167 function validate(props, propName, componentName, location, propFullName) {168 var propValue = props[propName];169 var propType = getPropType(propValue);170 if (propType !== 'object') {171 var locationName = ReactPropTypeLocationNames[location];172 return new Error('Invalid ' + locationName + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));173 }174 for (var key in shapeTypes) {175 var checker = shapeTypes[key];176 if (!checker) {177 continue;178 }179 var error = checker(propValue, key, componentName, location, propFullName + '.' + key);180 if (error) {181 return error;182 }183 }184 return null;185 }186 return createChainableTypeChecker(validate);187}188function isNode(propValue) {189 switch (typeof propValue) {190 case 'number':191 case 'string':192 case 'undefined':193 return true;194 case 'boolean':195 return !propValue;196 case 'object':197 if (Array.isArray(propValue)) {198 return propValue.every(isNode);199 }200 if (propValue === null || ReactElement.isValidElement(propValue)) {...

Full Screen

Full Screen

ChainTypes.js

Source:ChainTypes.js Github

copy

Full Screen

1import utils from "common/utils";2import Immutable from "immutable";3import {ChainTypes as grapheneChainTypes, ChainValidation} from "bitsharesjs";4const {object_type} = grapheneChainTypes;5function createChainableTypeChecker(validate) {6 function checkType(isRequired, props, propName, componentName, location) {7 componentName = componentName || ANONYMOUS;8 if (props[propName] == null) {9 if (isRequired) {10 return new Error(11 "Required " +12 location +13 " `" +14 propName +15 "` was not specified in " +16 ("`" + componentName + "`.")17 );18 }19 return null;20 } else {21 return validate(props, propName, componentName, location);22 }23 }24 let chainedCheckType = checkType.bind(null, false);25 chainedCheckType.isRequired = checkType.bind(null, true);26 return chainedCheckType;27}28function objectIdChecker(props, propName, componentName) {29 componentName = componentName || "ANONYMOUS";30 if (props[propName]) {31 let value = props[propName];32 if (typeof value === "string") {33 return utils.is_object_id(value)34 ? null35 : new Error(36 `${propName} in ${componentName} should be an object id`37 );38 } else if (typeof value === "object") {39 // TODO: check object type (probably we should require an object to be a tcomb structure)40 } else {41 return new Error(42 `${propName} in ${componentName} should be an object id or object`43 );44 }45 }46 // assume all ok47 return null;48}49function keyChecker(props, propName, componentName) {50 componentName = componentName || "ANONYMOUS";51 if (props[propName]) {52 let value = props[propName];53 if (typeof value === "string") {54 // TODO: check if it's valid key55 // PublicKey.fromPublicKeyString(value)56 return null;57 } else {58 return new Error(59 `${propName} in ${componentName} should be a key string`60 );61 }62 }63 // assume all ok64 return null;65}66function assetChecker(props, propName, componentName) {67 componentName = componentName || "ANONYMOUS";68 if (props[propName]) {69 let value = props[propName];70 if (typeof value === "string") {71 return null;72 } else if (typeof value === "object") {73 // TODO: check object type (probably we should require an object to be a tcomb structure)74 } else {75 return new Error(76 `${propName} of ${value} in ${componentName} should be an asset symbol or id`77 );78 }79 }80 // assume all ok81 return null;82}83function accountChecker(props, propName, componentName) {84 componentName = componentName || "ANONYMOUS";85 if (props[propName]) {86 let value = props[propName];87 if (typeof value === "string") {88 return null;89 if (90 utils.is_object_id(value) &&91 value.split(".")[1] === object_type.account92 ) {93 return null;94 } else {95 return new Error(96 `${propName} of ${value} in ${componentName} should be an account id`97 );98 }99 } else if (typeof value === "object") {100 if (101 value instanceof Map &&102 !!value.get("name") &&103 value.size == 1104 ) {105 // special case for BindToCurrentAccount106 return null;107 }108 // TODO: check object type (probably we should require an object to be a tcomb structure)109 } else {110 return new Error(111 `${propName} of ${value} in ${componentName} should be an account id`112 );113 }114 }115 // assume all ok116 return null;117}118function objectsListChecker(props, propName, componentName) {119 componentName = componentName || "ANONYMOUS";120 if (props[propName]) {121 let value = props[propName];122 if (123 Immutable.List.isList(value) ||124 Immutable.Set.isSet(value) ||125 value instanceof Object126 ) {127 return null;128 } else {129 return new Error(130 `${propName} in ${componentName} should be Immutable.List`131 );132 }133 }134 // assume all ok135 return null;136}137function assetsListChecker(props, propName, componentName) {138 componentName = componentName || "ANONYMOUS";139 if (props[propName]) {140 let value = props[propName];141 if (142 Immutable.List.isList(value) ||143 Immutable.Set.isSet(value) ||144 value instanceof Object145 ) {146 return null;147 } else {148 return new Error(149 `${propName} in ${componentName} should be Immutable.List`150 );151 }152 }153 // assume all ok154 return null;155}156function accountsListChecker(props, propName, componentName) {157 componentName = componentName || "ANONYMOUS";158 if (props[propName]) {159 let value = props[propName];160 if (161 Immutable.List.isList(value) ||162 Immutable.Set.isSet(value) ||163 value instanceof Object164 ) {165 return null;166 } else {167 return new Error(168 `${propName} in ${componentName} should be Immutable.List`169 );170 }171 }172 // assume all ok173 return null;174}175function accountNameChecker(props, propName, componentName) {176 componentName = componentName || "ANONYMOUS";177 if (props[propName]) {178 let value = props[propName];179 if (ChainValidation.is_account_name(value)) {180 return null;181 } else {182 return new Error(183 `${propName} value of ${value} in ${componentName} is not a valid account name`184 );185 }186 }187 // assume all ok188 return null;189}190let ChainObject = createChainableTypeChecker(objectIdChecker);191let ChainAccount = createChainableTypeChecker(accountChecker);192let ChainAccountName = createChainableTypeChecker(accountNameChecker);193let ChainKeyRefs = createChainableTypeChecker(keyChecker);194let ChainAddressBalances = createChainableTypeChecker(keyChecker);195let ChainAsset = createChainableTypeChecker(assetChecker);196let ChainObjectsList = createChainableTypeChecker(objectsListChecker);197let ChainAccountsList = createChainableTypeChecker(accountsListChecker);198let ChainAssetsList = createChainableTypeChecker(assetsListChecker);199export default {200 ChainObject,201 ChainAccount,202 ChainAccountName,203 ChainKeyRefs,204 ChainAddressBalances,205 ChainAsset,206 ChainObjectsList,207 ChainAccountsList,208 ChainAssetsList...

Full Screen

Full Screen

PropTypes.js

Source:PropTypes.js Github

copy

Full Screen

1import createChainableTypeChecker2 from 'react-prop-types/lib/utils/createChainableTypeChecker';3import ValidComponentChildren from './ValidComponentChildren';4export function requiredRoles(...roles) {5 return createChainableTypeChecker((props, propName, component) => {6 let missing;7 roles.every(role => {8 if (!ValidComponentChildren.some(9 props.children, child => child.props.bsRole === role10 )) {11 missing = role;12 return false;13 }14 return true;15 });16 if (missing) {17 return new Error(18 `(children) ${component} - Missing a required child with bsRole: ` +19 `${missing}. ${component} must have at least one child of each of ` +20 `the following bsRoles: ${roles.join(', ')}`21 );22 }23 return null;24 });25}26export function exclusiveRoles(...roles) {27 return createChainableTypeChecker((props, propName, component) => {28 let duplicate;29 roles.every(role => {30 const childrenWithRole = ValidComponentChildren.filter(31 props.children, child => child.props.bsRole === role32 );33 if (childrenWithRole.length > 1) {34 duplicate = role;35 return false;36 }37 return true;38 });39 if (duplicate) {40 return new Error(41 `(children) ${component} - Duplicate children detected of bsRole: ` +...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createChainableTypeChecker } = require('playwright/lib/utils/utils');2const { expect } = require('chai');3const customTypeChecker = createChainableTypeChecker((value) => {4 if (value === 'foo') {5 return null;6 }7 return new Error('Value is not foo');8});9expect('foo', 'foo').to.satisfy(customTypeChecker);10const { test, expect } = require('@playwright/test');11test('test', async ({ page }) => {12 expect('foo', 'foo').to.satisfy(customTypeChecker);13});14 expect(foo, foo).to.satisfy(customTypeChecker) - expected 'foo' to satisfy customTypeChecker:15 at Object.<anonymous> (test.js:7:11)16 at Object.<anonymous> (test.spec.js:4:1)17 at Object.<anonymous> (test.spec.js:1:1)18 at Module._compile (internal/modules/cjs/loader.js:1063:30)19 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)20 at Module.load (internal/modules/cjs/loader.js:928:32)21 at Function.Module._load (internal/modules/cjs/loader.js:769:14)22 at Module.require (internal/modules/cjs/loader.js:952:19)23 at require (internal/modules/cjs/helpers.js:88:18)24 at Object.<anonymous> (test.spec.js:1:1)25 0 passed (0.3s)26Test failed: expect(foo, foo).to.satisfy(customTypeChecker) - expected 'foo' to satisfy customTypeChecker:27 at Object.<anonymous> (test.js:7:11)28 at Object.<anonymous> (test.spec.js:4:1)29 at Object.<anonymous> (test.spec.js:1:1)30 at Module._compile (internal/modules/cjs/loader.js:1063:30)31 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createChainableTypeChecker } = require('@playwright/test/lib/utils/stackTrace');2const { expect } = require('@playwright/test');3const check = createChainableTypeChecker('MyCustomType');4expect.extend({5 toBeMyCustomType: check((actual) => {6 return {7 message: `Expected ${actual} to be MyCustomType`8 };9 }),10});11test('MyCustomType', async ({ page }) => {12 await page.click('text=Get started');13 await page.click('text=Docs');14 await page.click('text=API');15 await page.click('text=Class: Page');16 await page.click('

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createChainableTypeChecker } = require('playwright/lib/utils');2const { expect } = require('chai');3const isString = createChainableTypeChecker((value) => typeof value === 'string');4expect('test').to.be.a.string;5const { createChainableTypeChecker } = require('playwright/lib/utils');6const { expect } = require('chai');7const isString = createChainableTypeChecker((value) => typeof value === 'string');8expect('test').to.be.a(isString);9const { createChainableTypeChecker } = require('playwright/lib/utils');10const { expect } = require('chai');11const isString = createChainableTypeChecker((value) => typeof value === 'string');12expect('test').to.be.a(isString());13const { createChainableTypeChecker } = require('playwright/lib/utils');14const { expect } = require('chai');15const isString = createChainableTypeChecker((value) => typeof value === 'string');16expect('test').to.be.a(isString);17const { createChainableTypeChecker } = require('playwright/lib/utils');18const { expect } = require('chai');19const isString = createChainableTypeChecker((value) => typeof value === 'string');20expect('test').to.be.a(isString);21const { createChainableTypeChecker } = require('playwright/lib/utils');22const { expect } = require('chai');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createChainableTypeChecker } = require('playwright/lib/utils/utils').helper;2const isStringOrNumber = createChainableTypeChecker((actual) => {3 if (typeof actual !== 'string' && typeof actual !== 'number') {4 throw new Error('Expected to be string or number');5 }6});7const isStringOrNumberOrBoolean = createChainableTypeChecker((actual) => {8 if (typeof actual !== 'string' && typeof actual !== 'number' && typeof actual !== 'boolean') {9 throw new Error('Expected to be string, number or boolean');10 }11});12const isStringOrNumberOrBooleanOrArray = createChainableTypeChecker((actual) => {13 if (typeof actual !== 'string' && typeof actual !== 'number' && typeof actual !== 'boolean' && !Array.isArray(actual)) {14 throw new Error('Expected to be string, number, boolean or array');15 }16});17const isStringOrNumberOrObject = createChainableTypeChecker((actual) => {18 if (typeof actual !== 'string' && typeof actual !== 'number' && typeof actual !== 'object') {19 throw new Error('Expected to be string, number or object');20 }21});22const isStringOrNumberOrObjectOrArray = createChainableTypeChecker((actual) => {23 if (typeof actual !== 'string' && typeof actual !== 'number' && typeof actual !== 'object' && !Array.isArray(actual)) {24 throw new Error('Expected to be string, number, object or array');25 }26});27const isStringOrNumberOrObjectOrArrayOrBoolean = createChainableTypeChecker((actual) => {28 if (typeof actual !== 'string' && typeof actual !== 'number' && typeof actual !== 'object' && !Array.isArray(actual) && typeof actual !== 'boolean') {29 throw new Error('Expected to be string, number, object, array or boolean');30 }31});32const isStringOrNumberOrObjectOrArrayOrBooleanOrFunction = createChainableTypeChecker((actual) => {33 if (typeof actual !== 'string' && typeof actual !== 'number' && typeof actual !== 'object' && !Array.isArray(actual) && typeof actual !== 'boolean

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createChainableTypeChecker } = require('playwright/lib/utils/utils.js');2const { test } = require('@playwright/test');3const customType = createChainableTypeChecker(function (value) {4 return value === 'my custom type';5});6test('custom type', async ({ page }) => {7 await page.click(customType);8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createChainableTypeChecker } = require('@playwright/test/lib/utils');2const customTypeChecker = createChainableTypeChecker((value) => {3 if (value === 'custom') {4 return { pass: true };5 } else {6 return { pass: false, message: 'Value is not custom' };7 }8});9const { createType } = require('@playwright/test/lib/utils');10const customType = createType('custom', customTypeChecker);11const { createType } = require('@playwright/test/lib/utils');12const pageType = createType('page', (value) => {13 if (value instanceof Page) {14 return { pass: true };15 } else {16 return { pass: false, message: 'Value is not a page' };17 }18});19const { createType } = require('@playwright/test/lib/utils');20const contextType = createType('context', (value) => {21 if (value instanceof BrowserContext) {22 return { pass: true };23 } else {24 return { pass: false, message: 'Value is not a context' };25 }26});27const { createType } = require('@playwright/test/lib/utils');28const browserType = createType('browser', (value) => {29 if (value instanceof Browser) {30 return { pass: true };31 } else {32 return { pass: false, message: 'Value is not a browser' };33 }34});35const { createType } = require('@playwright/test/lib/utils');36const elementHandleType = createType('elementHandle', (value) => {37 if (value instanceof ElementHandle) {38 return { pass: true };39 } else {40 return { pass: false, message: 'Value is not an elementHandle' };41 }42});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createChainableTypeChecker } = require('playwright/lib/utils/utils');2const customTypeChecker = createChainableTypeChecker(3 value => {4 if (value === 'foo') {5 return 'foo';6 }7 return 'bar';8 },9);10const foo = customTypeChecker('foo');11const bar = customTypeChecker('bar');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createChainableTypeChecker } = require('playwright-core/lib/server/common/utils');2const myCustomSelector = createChainableTypeChecker(3 (selector) => {4 if (typeof selector !== 'string') {5 return { expected: 'string', got: typeof selector };6 }7 return true;8 },9 (selector) => {10 return {11 message: () => `Invalid selector: ${selector}`,12 };13 }14);15const myCustomSelector2 = createChainableTypeChecker(16 (selector) => {17 if (typeof selector !== 'string') {18 return { expected: 'string', got: typeof selector };19 }20 return true;21 },22 (selector) => {23 return {24 message: () => `Invalid selector: ${selector}`,25 };26 }27);28class MyPage {29 constructor(page) {30 this.page = page;31 }32 async myCustomSelector(selector) {33 await this.page.click(selector);34 }35 async myCustomSelector2(selector) {36 await this.page.click(selector);37 }38}39module.exports = {40};41const { MyPage, myCustomSelector, myCustomSelector2 } = require('./test');42describe('My Test', () => {43 let page;44 let myPage;45 beforeAll(async () => {46 page = await browser.newPage();47 myPage = new MyPage(page);48 });49 afterAll(async () => {50 await page.close();51 });52 test('test', async () => {53 await myPage.myCustomSelector('myCustomSelector');54 await myPage.myCustomSelector2('myCustomSelector2');55 });56});

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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