Best JavaScript code snippet using playwright-internal
index.js
Source:index.js
...288 }289};290exports.assert = {291 // Unknowns.292 undefined: (value) => assertType(is.undefined(value), 'undefined', value),293 string: (value) => assertType(is.string(value), 'string', value),294 number: (value) => assertType(is.number(value), 'number', value),295 bigint: (value) => assertType(is.bigint(value), 'bigint', value),296 // eslint-disable-next-line @typescript-eslint/ban-types297 function_: (value) => assertType(is.function_(value), 'Function', value),298 null_: (value) => assertType(is.null_(value), 'null', value),299 class_: (value) => assertType(is.class_(value), "Class" /* class_ */, value),300 boolean: (value) => assertType(is.boolean(value), 'boolean', value),301 symbol: (value) => assertType(is.symbol(value), 'symbol', value),302 numericString: (value) => assertType(is.numericString(value), "string with a number" /* numericString */, value),303 array: (value, assertion) => {304 const assert = assertType;305 assert(is.array(value), 'Array', value);306 if (assertion) {307 value.forEach(assertion);308 }309 },310 buffer: (value) => assertType(is.buffer(value), 'Buffer', value),311 nullOrUndefined: (value) => assertType(is.nullOrUndefined(value), "null or undefined" /* nullOrUndefined */, value),312 object: (value) => assertType(is.object(value), 'Object', value),313 iterable: (value) => assertType(is.iterable(value), "Iterable" /* iterable */, value),314 asyncIterable: (value) => assertType(is.asyncIterable(value), "AsyncIterable" /* asyncIterable */, value),315 generator: (value) => assertType(is.generator(value), 'Generator', value),316 asyncGenerator: (value) => assertType(is.asyncGenerator(value), 'AsyncGenerator', value),317 nativePromise: (value) => assertType(is.nativePromise(value), "native Promise" /* nativePromise */, value),318 promise: (value) => assertType(is.promise(value), 'Promise', value),319 generatorFunction: (value) => assertType(is.generatorFunction(value), 'GeneratorFunction', value),320 asyncGeneratorFunction: (value) => assertType(is.asyncGeneratorFunction(value), 'AsyncGeneratorFunction', value),321 // eslint-disable-next-line @typescript-eslint/ban-types322 asyncFunction: (value) => assertType(is.asyncFunction(value), 'AsyncFunction', value),323 // eslint-disable-next-line @typescript-eslint/ban-types324 boundFunction: (value) => assertType(is.boundFunction(value), 'Function', value),325 regExp: (value) => assertType(is.regExp(value), 'RegExp', value),326 date: (value) => assertType(is.date(value), 'Date', value),327 error: (value) => assertType(is.error(value), 'Error', value),328 map: (value) => assertType(is.map(value), 'Map', value),329 set: (value) => assertType(is.set(value), 'Set', value),330 weakMap: (value) => assertType(is.weakMap(value), 'WeakMap', value),331 weakSet: (value) => assertType(is.weakSet(value), 'WeakSet', value),332 int8Array: (value) => assertType(is.int8Array(value), 'Int8Array', value),333 uint8Array: (value) => assertType(is.uint8Array(value), 'Uint8Array', value),334 uint8ClampedArray: (value) => assertType(is.uint8ClampedArray(value), 'Uint8ClampedArray', value),335 int16Array: (value) => assertType(is.int16Array(value), 'Int16Array', value),336 uint16Array: (value) => assertType(is.uint16Array(value), 'Uint16Array', value),337 int32Array: (value) => assertType(is.int32Array(value), 'Int32Array', value),338 uint32Array: (value) => assertType(is.uint32Array(value), 'Uint32Array', value),339 float32Array: (value) => assertType(is.float32Array(value), 'Float32Array', value),340 float64Array: (value) => assertType(is.float64Array(value), 'Float64Array', value),341 bigInt64Array: (value) => assertType(is.bigInt64Array(value), 'BigInt64Array', value),342 bigUint64Array: (value) => assertType(is.bigUint64Array(value), 'BigUint64Array', value),343 arrayBuffer: (value) => assertType(is.arrayBuffer(value), 'ArrayBuffer', value),344 sharedArrayBuffer: (value) => assertType(is.sharedArrayBuffer(value), 'SharedArrayBuffer', value),345 dataView: (value) => assertType(is.dataView(value), 'DataView', value),346 urlInstance: (value) => assertType(is.urlInstance(value), 'URL', value),347 urlString: (value) => assertType(is.urlString(value), "string with a URL" /* urlString */, value),348 truthy: (value) => assertType(is.truthy(value), "truthy" /* truthy */, value),349 falsy: (value) => assertType(is.falsy(value), "falsy" /* falsy */, value),350 nan: (value) => assertType(is.nan(value), "NaN" /* nan */, value),351 primitive: (value) => assertType(is.primitive(value), "primitive" /* primitive */, value),352 integer: (value) => assertType(is.integer(value), "integer" /* integer */, value),353 safeInteger: (value) => assertType(is.safeInteger(value), "integer" /* safeInteger */, value),354 plainObject: (value) => assertType(is.plainObject(value), "plain object" /* plainObject */, value),355 typedArray: (value) => assertType(is.typedArray(value), "TypedArray" /* typedArray */, value),356 arrayLike: (value) => assertType(is.arrayLike(value), "array-like" /* arrayLike */, value),357 domElement: (value) => assertType(is.domElement(value), "HTMLElement" /* domElement */, value),358 observable: (value) => assertType(is.observable(value), 'Observable', value),359 nodeStream: (value) => assertType(is.nodeStream(value), "Node.js Stream" /* nodeStream */, value),360 infinite: (value) => assertType(is.infinite(value), "infinite number" /* infinite */, value),361 emptyArray: (value) => assertType(is.emptyArray(value), "empty array" /* emptyArray */, value),362 nonEmptyArray: (value) => assertType(is.nonEmptyArray(value), "non-empty array" /* nonEmptyArray */, value),363 emptyString: (value) => assertType(is.emptyString(value), "empty string" /* emptyString */, value),364 nonEmptyString: (value) => assertType(is.nonEmptyString(value), "non-empty string" /* nonEmptyString */, value),365 emptyStringOrWhitespace: (value) => assertType(is.emptyStringOrWhitespace(value), "empty string or whitespace" /* emptyStringOrWhitespace */, value),366 emptyObject: (value) => assertType(is.emptyObject(value), "empty object" /* emptyObject */, value),367 nonEmptyObject: (value) => assertType(is.nonEmptyObject(value), "non-empty object" /* nonEmptyObject */, value),368 emptySet: (value) => assertType(is.emptySet(value), "empty set" /* emptySet */, value),369 nonEmptySet: (value) => assertType(is.nonEmptySet(value), "non-empty set" /* nonEmptySet */, value),370 emptyMap: (value) => assertType(is.emptyMap(value), "empty map" /* emptyMap */, value),371 nonEmptyMap: (value) => assertType(is.nonEmptyMap(value), "non-empty map" /* nonEmptyMap */, value),372 // Numbers.373 evenInteger: (value) => assertType(is.evenInteger(value), "even integer" /* evenInteger */, value),374 oddInteger: (value) => assertType(is.oddInteger(value), "odd integer" /* oddInteger */, value),375 // Two arguments.376 directInstanceOf: (instance, class_) => assertType(is.directInstanceOf(instance, class_), "T" /* directInstanceOf */, instance),377 inRange: (value, range) => assertType(is.inRange(value, range), "in range" /* inRange */, value),378 // Variadic functions.379 any: (predicate, ...values) => assertType(is.any(predicate, ...values), "predicate returns truthy for any value" /* any */, values),380 all: (predicate, ...values) => assertType(is.all(predicate, ...values), "predicate returns truthy for all values" /* all */, values)381};382// Some few keywords are reserved, but we'll populate them for Node.js users383// See https://github.com/Microsoft/TypeScript/issues/2536384Object.defineProperties(is, {385 class: {386 value: is.class_387 },388 function: {389 value: is.function_390 },391 null: {392 value: is.null_393 }394});...
definitions.js
Source:definitions.js
...103});104const SassFunction = defineType('SassFunction', {105 fields: {106 id: {107 validate: assertType(Identifier),108 },109 params: {110 optional: true,111 validate: () =>112 arrayOf(113 assertOneOf([assertType(AssignmentPattern), assertType(Identifier)])114 ),115 },116 body: {117 validate: () => assertType(BlockStatement),118 },119 },120 generate(printer, node, parent) {121 printer.token('@function');122 printer.space();123 printer.print(node.id, parent);124 printer.token('(');125 if (Array.isArray(node.params)) {126 for (let i = 0; i < node.params.length; i++) {127 printer.print(node.params[i], node);128 if (i !== node.params.length - 1) {129 printer.token(',');130 printer.space();131 }132 }133 }134 printer.token(')');135 printer.space();136 printer.print(node.body, parent);137 },138});139const SassList = defineType('SassList', {140 fields: {141 elements: {142 validate: () =>143 arrayOf(144 assertOneOf([145 assertType(SassBoolean),146 assertType(SassList),147 assertType(SassMap),148 assertType(SassNumber),149 assertType(SassString),150 ])151 ),152 },153 },154 generate(printer, node) {155 printer.token('(');156 for (let i = 0; i < node.elements.length; i++) {157 printer.print(node.elements[i], node);158 if (i !== node.elements.length - 1) {159 printer.token(',');160 printer.space();161 }162 }163 printer.token(')');164 },165});166const SassMap = defineType('SassMap', {167 fields: {168 properties: {169 validate: () => arrayOf(assertType(SassMapProperty)),170 },171 },172 generate(printer, node) {173 printer.blockStart('(');174 for (let i = 0; i < node.properties.length; i++) {175 printer.print(node.properties[i]);176 if (i !== node.properties.length - 1) {177 printer.token(',');178 printer.newline();179 }180 }181 printer.blockEnd(')');182 },183});184const SassMapProperty = defineType('SassMapProperty', {185 fields: {186 key: {187 validate: assertType(Identifier),188 },189 value: {190 validate: () =>191 assertOneOf([SassBoolean, SassNumber, SassString, SassList, SassMap]),192 },193 quoted: {194 optional: true,195 validate: assertValueType('boolean'),196 },197 },198 generate(printer, node) {199 if (node.quoted) {200 printer.token(`'`);201 printer.print(node.key, node);202 printer.token(`'`);203 } else {204 printer.print(node.key, node);205 }206 printer.token(':');207 printer.space();208 printer.print(node.value, node);209 },210});211const SassMixin = defineType('SassMixin', {212 fields: {213 id: {214 validate: assertType(Identifier),215 },216 params: {217 optional: true,218 validate: () =>219 arrayOf(220 assertOneOf([assertType(AssignmentPattern), assertType(Identifier)])221 ),222 },223 body: {224 validate: assertType(BlockStatement),225 },226 },227 generate(printer, node, parent) {228 printer.token('@mixin');229 printer.space();230 printer.print(node.id, parent);231 printer.token('(');232 if (Array.isArray(node.params)) {233 for (let i = 0; i < node.params.length; i++) {234 printer.print(node.params[i], node);235 if (i !== node.params.length - 1) {236 printer.token(',');237 printer.space();238 }239 }240 }241 printer.token(')');242 printer.space();243 printer.print(node.body, parent);244 },245});246const SassNumber = defineType('SassNumber', {247 fields: {248 value: {249 validate: assertValueType('number'),250 },251 },252 generate(printer, node) {253 printer.token(node.value);254 },255});256const SassString = defineType('SassString', {257 fields: {258 value: {259 validate: assertValueType('string'),260 },261 },262 generate(printer, node) {263 printer.token(`'${node.value}'`);264 },265});266//-------------------------------------------------------------------------------267// Calls268//-------------------------------------------------------------------------------269const SassMixinCall = defineType('SassMixinCall', {270 fields: {271 id: {272 validate: assertType(Identifier),273 },274 params: {275 optional: true,276 validate: () =>277 arrayOf(278 assertOneOf([279 assertType(Identifier),280 assertType(SassBoolean),281 assertType(SassList),282 assertType(SassMap),283 assertType(SassNumber),284 assertType(SassString),285 ])286 ),287 },288 body: {289 optional: true,290 validate: assertType(BlockStatement),291 },292 },293 generate(printer, node) {294 printer.token('@include');295 printer.space();296 printer.print(node.id);297 printer.token('(');298 if (Array.isArray(node.params)) {299 for (let i = 0; i < node.params.length; i++) {300 printer.token('$');301 printer.print(node.params[i], node);302 if (i !== node.params.length - 1) {303 printer.token(',');304 printer.space();305 }306 }307 }308 printer.token(')');309 if (node.body) {310 printer.print(node.body, node);311 }312 printer.token(';');313 },314});315//-------------------------------------------------------------------------------316// Rules317//-------------------------------------------------------------------------------318const Rule = defineType('Rule', {319 fields: {320 declarations: {321 validate: () => arrayOf(assertType(Declaration)),322 },323 selectors: {324 validate: arrayOf(assertValueType('string')),325 },326 },327 generate(printer, node) {328 printer.token(node.selectors.join(', '));329 printer.space();330 printer.blockStart();331 for (let i = 0; i < node.declarations.length; i++) {332 const declaration = node.declarations[i];333 printer.print(declaration, node);334 if (i !== node.declarations.length - 1) {335 printer.newline();336 }337 }338 printer.blockEnd();339 },340});341const Declaration = defineType('Declaration', {342 fields: {343 property: {344 validate: assertValueType('string'),345 },346 value: {347 validate: assertValueType('string'),348 },349 },350 generate(printer, node) {351 printer.token(node.property);352 printer.token(':');353 printer.space();354 printer.token(node.value);355 printer.token(';');356 },357});358//-------------------------------------------------------------------------------359// At-Rules and directives360//-------------------------------------------------------------------------------361const AtRule = defineType('AtRule', {362 fields: {363 name: {364 validate: assertValueType('string'),365 },366 media: {367 validate: assertValueType('string'),368 },369 children: {370 validate: arrayOf(assertOneOf([assertType(Rule)])),371 },372 },373 generate(printer, node) {374 printer.token(`@${node.name}`);375 printer.space();376 printer.token(node.media);377 printer.space();378 printer.blockStart();379 for (let i = 0; i < node.children.length; i++) {380 printer.print(node.children[i], node);381 if (i !== node.children.length - 1) {382 printer.newline();383 }384 }385 printer.blockEnd();386 },387});388const AtContent = defineType('AtContent', {389 fields: {},390 generate(printer, node, parent) {391 if (parent.body.indexOf(node) !== 0) {392 printer.maybeNewline();393 }394 printer.token('@content;');395 },396});397const AtReturn = defineType('AtReturn', {398 fields: {399 argument: {400 validate: assertAny,401 },402 },403 generate(printer, node, parent) {404 if (parent.body.indexOf(node) !== 0) {405 printer.maybeNewline();406 }407 printer.token('@return');408 printer.space();409 printer.print(node.argument, node);410 printer.token(';');411 },412});413//-------------------------------------------------------------------------------414// Assignment415//-------------------------------------------------------------------------------416const Assignment = defineType('Assignment', {417 fields: {418 id: {419 validate: assertType(Identifier),420 },421 init: {422 validate: () =>423 assertOneOf([424 assertType(CallExpression),425 assertType(SassBoolean),426 assertType(SassColor),427 assertType(SassList),428 assertType(SassMap),429 assertType(SassNumber),430 assertType(SassString),431 ]),432 },433 default: {434 optional: true,435 validate: assertValueType('boolean'),436 },437 global: {438 optional: true,439 validate: assertValueType('boolean'),440 },441 },442 generate(printer, node, parent) {443 printer.print(node.id, node);444 printer.token(':');445 printer.space();446 printer.print(node.init, node);447 if (node.default) {448 printer.space();449 printer.token('!default');450 if (node.global) {451 printer.space();452 }453 }454 if (node.global) {455 printer.token('!global');456 }457 printer.token(';');458 if (parent) {459 // We have a couple of options for the block we may be operating in, in460 // this case we'll check for children or body and check if the collection461 // exists462 const collection = parent.children || parent.body;463 // If we have a collection, and there are more than one element in the464 // collection, then we can safely determine if we need to apply a newline465 // after an assignment466 if (collection && collection.length > 1) {467 const assignments = collection.filter(468 node => node.type === Assignment.type469 );470 if (471 assignments.length === 1 ||472 assignments.indexOf(node) === assignments.length - 1473 ) {474 printer.newline();475 }476 }477 }478 },479});480const AssignmentPattern = defineType('AssignmentPattern', {481 fields: {482 left: {483 validate: assertType(Identifier),484 },485 right: {486 validate: assertAny,487 },488 },489 generate(printer, node) {490 printer.print(node.left, node);491 printer.token(':');492 printer.space();493 printer.print(node.right, node);494 },495});496const RestPattern = defineType('RestPattern', {497 fields: {498 id: {499 validate: assertType(Identifier),500 },501 },502 generate(printer, node, parent) {503 printer.print(node.id, parent);504 printer.token('...');505 },506});507//-------------------------------------------------------------------------------508// Imports509//-------------------------------------------------------------------------------510const SassImport = defineType('SassImport', {511 fields: {512 path: {513 validate: assertValueType('string'),514 },515 },516 generate(printer, node) {517 printer.token('@import');518 printer.space();519 printer.token(`'${node.path}'`);520 printer.token(';');521 },522});523//-------------------------------------------------------------------------------524// Control structures525//-------------------------------------------------------------------------------526const IfStatement = defineType('IfStatement', {527 fields: {528 test: {529 validate: assertAny,530 },531 consequent: {532 optional: true,533 validate: assertType(BlockStatement),534 },535 alternate: {536 optional: true,537 validate: () =>538 assertOneOf([assertType(IfStatement), assertType(BlockStatement)]),539 },540 },541 generate(printer, node, parent) {542 if (parent && parent.type === IfStatement.type) {543 printer.space();544 printer.token('if');545 } else {546 printer.token('@if');547 }548 printer.space();549 printer.print(node.test, node);550 printer.print(node.consequent, node);551 if (node.alternate) {552 printer.token('@else');553 printer.print(node.alternate, node);554 }555 },556});557//-------------------------------------------------------------------------------558// Logical expressions559//-------------------------------------------------------------------------------560const LogicalExpression = defineType('LogicalExpression', {561 fields: {562 left: {563 validate: assertAny,564 },565 operator: {566 validate: assertValueType('string'),567 },568 right: {569 validate: assertAny,570 },571 },572 generate(printer, node) {573 printer.print(node.left, node);574 printer.space();575 printer.token(node.operator);576 printer.space();577 printer.print(node.right, node);578 },579});580//-------------------------------------------------------------------------------581// Call expressions582//-------------------------------------------------------------------------------583const CallExpression = defineType('CallExpression', {584 fields: {585 callee: {586 validate: assertType(Identifier),587 },588 arguments: {589 optional: true,590 validate: arrayOf(assertAny),591 },592 },593 generate(printer, node) {594 printer.print(node.callee);595 printer.token('(');596 if (Array.isArray(node.arguments)) {597 for (let i = 0; i < node.arguments.length; i++) {598 printer.print(node.arguments[i], node);599 if (i !== node.arguments.length - 1) {600 printer.token(',');601 printer.space();602 }603 }604 }605 printer.token(')');606 },607});608//-------------------------------------------------------------------------------609// StyleSheet610//-------------------------------------------------------------------------------611const StyleSheet = defineType('StyleSheet', {612 fields: {613 children: {614 validate: arrayOf(615 assertOneOf([616 assertType(Assignment),617 assertType(AtRule),618 assertType(Comment),619 assertType(IfStatement),620 assertType(Rule),621 assertType(SassFunction),622 assertType(SassImport),623 assertType(SassMixin),624 assertType(SassMixinCall),625 ])626 ),627 },628 },629 generate(printer, node) {630 // TODO: print leading comments631 for (let i = 0; i < node.children.length; i++) {632 printer.print(node.children[i], node);633 if (i !== node.children.length - 1) {634 printer.newline();635 }636 }637 },638});...
test_rsvp.js
Source:test_rsvp.js
1import RSVP from 'rsvp';2import { all, race, resolve } from 'rsvp';3/** Static assertion that `value` has type `T` */4// Disable tslint here b/c the generic is used to let us do a type coercion and5// validate that coercion works for the type value "passed into" the function.6// tslint:disable-next-line:no-unnecessary-generics7declare function assertType<T>(value: T): void;8async function testAsyncAwait() {9 const awaitedNothing = await RSVP.resolve();10 const awaitedValue = await RSVP.resolve('just a value');11 async function returnsAPromise(): RSVP.Promise<string> {12 return RSVP.resolve('look, a string');13 }14 assertType<RSVP.Promise<string>>(returnsAPromise());15 assertType<string>(await returnsAPromise());16}17function testCast() {18 RSVP.Promise.cast('foo').then(value => {19 assertType<string>(value);20 });21 RSVP.cast(42).then(value => {22 assertType<number>(value);23 });24}25function testConfigure() {26 assertType<void>(RSVP.configure('name', { with: 'some value' }));27 assertType<{}>(RSVP.configure('name'));28}29function testAsap() {30 const result = RSVP.asap(something => {31 console.log(something);32 }, 'srsly');33 assertType<void>(result);34}35function testAsync() {36 const result = RSVP.async(something => {37 console.log(something);38 }, 'rly srsly');39 assertType<void>(result);40}41function testPromise() {42 const promiseOfString = new RSVP.Promise((resolve: any, reject: any) => resolve('some string'));43 assertType<RSVP.Promise<number>>(promiseOfString.then((s: string) => s.length));44}45function testPromiseWithLabel() {46 new RSVP.Promise((resolve: any, reject: any) => resolve('foo'), 'my promise');47}48function testAll() {49 const imported = all([]);50 const empty = RSVP.Promise.all([]);51 const everyPromise = RSVP.all([52 'string',53 RSVP.resolve(42),54 RSVP.resolve({ hash: 'with values' }),55 ]);56 assertType<RSVP.Promise<[string, number, { hash: string }]>>(everyPromise);57 const anyFailure = RSVP.all([12, 'strings', RSVP.reject('anywhere')]);58 assertType<RSVP.Promise<{}>>(anyFailure);59 let promise1 = RSVP.resolve(1);60 let promise2 = RSVP.resolve('2');61 let promise3 = RSVP.resolve({ key: 13 });62 RSVP.Promise.all([promise1, promise2, promise3], 'my label').then(function(array) {63 assertType<number>(array[0]);64 assertType<string>(array[1]);65 assertType<{ key: number }>(array[2]);66 });67}68function testAllSettled() {69 const resolved1 = RSVP.resolve(1);70 const resolved2 = RSVP.resolve('wat');71 const rejected = RSVP.reject(new Error('oh teh noes'));72 const pending = new RSVP.Promise<{ neato: string }>((resolve, reject) => {73 if ('something') {74 resolve({ neato: 'yay' });75 } else {76 reject('nay');77 }78 });79 // Types flow into resolution properly80 RSVP.allSettled([resolved1, resolved2, rejected, pending]).then(states => {81 assertType<RSVP.PromiseState<number>>(states[0]);82 assertType<RSVP.PromiseState<string>>(states[1]);83 assertType<RSVP.PromiseState<never>>(states[2]);84 assertType<RSVP.PromiseState<{ neato: string }>>(states[3]);85 });86 // Switching on state gives the correctly available items.87 RSVP.allSettled([resolved1, resolved2, rejected, pending]).then(states => {88 states.forEach(element => {89 switch (element.state) {90 case RSVP.State.fulfilled:91 assertType<RSVP.Resolved<typeof element.value>>(element);92 break;93 case RSVP.State.rejected:94 assertType<RSVP.Rejected<typeof element.reason>>(element);95 break;96 case RSVP.State.pending:97 assertType<RSVP.Pending>(element);98 break;99 default:100 // Someday maybe TS will have exhaustiveness checks.101 break;102 }103 });104 });105}106function testDefer() {107 let deferred = RSVP.defer<string>();108 deferred.resolve('Success!');109 deferred.promise.then(function(value) {110 assertType<string>(value);111 });112}113// Using this to differentiate the types cleanly114type A1 = Array<{ arg: boolean }>;115type D1 = number;116type D2 = string;117type D3 = { some: boolean };118declare const nodeFn1Arg1CbParam: (arg1: A1, callback: (err: any, data: D1) => void) => void;119declare const nodeFn1Arg2CbParam: (120 arg1: A1,121 callback: (err: any, data1: D1, data2: D2) => void122) => void;123declare const nodeFn1Arg3CbParam: (124 arg1: A1,125 callback: (err: any, data1: D1, data2: D2, data3: D3) => void126) => void;127function testDenodeify() {128 // version with no `options` or `options: false`, and single T129 assertType<(value: A1) => RSVP.Promise<D1>>(RSVP.denodeify(nodeFn1Arg1CbParam));130 assertType<(value: A1) => RSVP.Promise<D1>>(RSVP.denodeify(nodeFn1Arg1CbParam, false));131 // version with no `options` or `options: false`, and multiple T132 assertType<(value: A1) => RSVP.Promise<D1>>(RSVP.denodeify(nodeFn1Arg2CbParam));133 assertType<(value: A1) => RSVP.Promise<D1>>(RSVP.denodeify(nodeFn1Arg3CbParam));134 assertType<(value: A1) => RSVP.Promise<D1>>(RSVP.denodeify(nodeFn1Arg2CbParam, false));135 assertType<(value: A1) => RSVP.Promise<D1>>(RSVP.denodeify(nodeFn1Arg3CbParam, false));136 // version with `options: true` and single or multiple T137 assertType<(value: A1) => RSVP.Promise<[D1]>>(RSVP.denodeify(nodeFn1Arg1CbParam, true));138 assertType<(value: A1) => RSVP.Promise<[D1, D2]>>(RSVP.denodeify(nodeFn1Arg2CbParam, true));139 assertType<(value: A1) => RSVP.Promise<[D1, D2, D3]>>(RSVP.denodeify(nodeFn1Arg3CbParam, true));140 // We can't actually map the key names here, because we would need full-on141 // dependent typing to use the *values of an array* as the keys of the142 // resulting object.143 assertType<(value: A1) => RSVP.Promise<{ first: D1 }>>(144 RSVP.denodeify(nodeFn1Arg1CbParam, ['first'])145 );146 assertType<(value: A1) => RSVP.Promise<{ first: D1; second: D2 }>>(147 RSVP.denodeify(nodeFn1Arg2CbParam, ['first', 'second'])148 );149 assertType<(value: A1) => RSVP.Promise<{ first: D1; second: D2; third: D3 }>>(150 RSVP.denodeify(nodeFn1Arg3CbParam, ['first', 'second', 'third'])151 );152 const foo = RSVP.denodeify(nodeFn1Arg2CbParam, ['quux', 'baz']);153 foo([{ arg: true }]).then(value => {154 console.log(value.quux + 1);155 console.log(value.baz.length);156 });157}158function testFilter() {159 RSVP.filter([RSVP.resolve(1), RSVP.resolve(2)], item => item > 1, 'over one').then(results => {160 assertType<number[]>(results);161 });162 RSVP.filter(163 [RSVP.resolve('a string'), RSVP.resolve(112233)],164 item => String(item).length < 10,165 'short string'166 ).then(results => {167 assertType<Array<string | number>>(results);168 });169 // This is the best we can do: we can't actually write the full type here,170 // which would be `assertType<never>(results)`, but TS can't infer that.171 const isString = (item: any): item is string => typeof item === 'string';172 RSVP.filter([RSVP.reject('for any reason')], isString).then(results => {173 assertType<{}>(results);174 });175}176function testHash() {177 let promises = {178 myPromise: RSVP.resolve(1),179 yourPromise: RSVP.resolve('2'),180 theirPromise: RSVP.resolve({ key: 3 }),181 notAPromise: 4,182 };183 RSVP.hash(promises, 'my label').then(function(hash) {184 assertType<number>(hash.myPromise);185 assertType<string>(hash.yourPromise);186 assertType<{ key: number }>(hash.theirPromise);187 assertType<number>(hash.notAPromise);188 });189}190function testHashSettled() {191 function isFulfilled<T>(state: RSVP.PromiseState<T>): state is RSVP.Resolved<T> {192 return state.state === RSVP.State.fulfilled;193 }194 let promises = {195 myPromise: RSVP.Promise.resolve(1),196 yourPromise: RSVP.Promise.resolve('2'),197 theirPromise: RSVP.Promise.resolve({ key: 3 }),198 notAPromise: 4,199 };200 RSVP.hashSettled(promises).then(function(hash) {201 if (isFulfilled(hash.myPromise)) {202 assertType<number>(hash.myPromise.value);203 }204 if (isFulfilled(hash.yourPromise)) {205 assertType<string>(hash.yourPromise.value);206 }207 if (isFulfilled(hash.theirPromise)) {208 assertType<{ key: number }>(hash.theirPromise.value);209 }210 if (isFulfilled(hash.notAPromise)) {211 assertType<number>(hash.notAPromise.value);212 }213 });214}215function testMap() {216 RSVP.map([RSVP.resolve(1), RSVP.resolve(2)], item => item + 1, 'add one').then(results => {217 assertType<number[]>(results);218 assertType<{ length: 2 }>(results);219 });220 RSVP.map([RSVP.resolve('a string'), RSVP.resolve(112233)], String).then(results => {221 assertType<string[]>(results);222 assertType<{ length: 2 }>(results);223 });224 // This is the best we can do: we can't actually write the full type here,225 // which would be `assertType<never>(results)`, but TS can't infer that.226 RSVP.map([RSVP.reject('for any reason')], String).then(results => {227 assertType<{}>(results);228 });229}230function testRace() {231 const imported = race([]);232 const firstPromise = RSVP.race([{ notAPromise: true }, RSVP.resolve({ some: 'value' })]);233 assertType<RSVP.Promise<{ notAPromise: boolean } | { some: string }>>(firstPromise);234 let promise1 = RSVP.resolve(1);235 let promise2 = RSVP.resolve('2');236 RSVP.Promise.race([promise1, promise2], 'my label').then(function(result) {237 assertType<string | number>(result);238 });239}240function testReject() {241 assertType<RSVP.Promise<never>>(RSVP.reject());242 assertType<RSVP.Promise<never>>(RSVP.reject('this is a string'));243 RSVP.reject({ ok: false }).catch(reason => {244 console.log(`${reason} could be anything`);245 });246 RSVP.reject({ ok: false }, 'some label').catch((reason: any) => reason.ok);247 let promise = RSVP.Promise.reject(new Error('WHOOPS'));248}249function testResolve() {250 assertType<RSVP.Promise<void>>(RSVP.resolve());251 assertType<RSVP.Promise<string>>(RSVP.resolve('this is a string'));252 assertType<RSVP.Promise<string>>(RSVP.resolve(RSVP.resolve('nested')));253 assertType<RSVP.Promise<string>>(RSVP.resolve(Promise.resolve('nested')));254 let promise = RSVP.Promise.resolve(1);255 let imported = resolve(1);256}257function testRethrow() {258 RSVP.reject(new Error('all the badness'))259 .catch(RSVP.rethrow)260 .then(value => {261 assertType<void>(value);262 })263 .catch(reason => {264 if (reason instanceof Error) {265 console.log(reason);266 }267 });268}269function testOnAndOff() {270 RSVP.on('error', (reason: Error) => {271 console.log(`it was an error: ${reason}`);272 });273 RSVP.off('whatever', (value: any) => {274 console.log(275 `any old value will do: ${value !== undefined && value !== null276 ? value.toString()277 : 'even undefined'}`278 );279 });280}281function testAssignableToPromise() {282 const promise: Promise<number> = RSVP.resolve(0);...
e7ipc2-types.test.ts
Source:e7ipc2-types.test.ts
1import {2 DefineCommands,3 Client,4 OK,5 ERR,6 Result,7 CommandOptions,8 CommandReturn,9 Server,10 defineHandlers,11} from '@/e7ipc2-types'12import { assertType, expectType } from './assertType'13type ThenArg<T> = T extends PromiseLike<infer U>14 ? U15 : T extends (...args: any[]) => PromiseLike<infer V>16 ? V17 : T18type Commands = DefineCommands<{19 com1: {20 opts: {21 a: number22 b: string23 }24 ret: number25 }26 com2: {27 ret: {28 x: number29 }30 }31 com3: {32 opts: {33 a: number34 b?: string35 }36 ret: string37 }38 com4: {39 x: Record<string, unknown>40 y: number41 }42}>43describe('e7ipc2-types', () => {44 test('DefineCommands', () => {45 assertType.equal<keyof Commands, 'com1' | 'com2' | 'com3'>()46 assertType.notEqual<keyof Commands, 'com1' | 'com2' | 'com3'>(false)47 })48 test('client.invoke(), options and return types', async () => {49 const client: Client<Commands> = { invoke: () => {} } as any50 const opts1 = { $cmd: 'com1', a: 0, b: 'B' } as const51 const opts2 = { $cmd: 'com2' } as const52 const opts3a = { $cmd: 'com3', a: 0 } as const53 const opts3b = { $cmd: 'com3', a: 0, b: 'B' } as const54 const r1 = client.invoke(opts1)55 const r2 = client.invoke(opts2)56 const r3a = client.invoke(opts3a)57 const r3b = client.invoke(opts3b)58 type OptsCom1 = CommandOptions<Commands, 'com1'>59 type OptsCom2 = CommandOptions<Commands, 'com2'>60 type OptsCom3 = CommandOptions<Commands, 'com3'>61 assertType.assignable<typeof opts1, OptsCom1>()62 assertType.notAssignable<typeof opts1, OptsCom1>(false)63 assertType.assignable<typeof opts2, OptsCom1>(false)64 assertType.notAssignable<typeof opts2, OptsCom1>()65 assertType.assignable<typeof opts2, OptsCom2>()66 assertType.notAssignable<typeof opts2, OptsCom2>(false)67 assertType.assignable<typeof opts3a, OptsCom2>(false)68 assertType.notAssignable<typeof opts3a, OptsCom2>()69 assertType.assignable<typeof opts3a, OptsCom3>()70 assertType.notAssignable<typeof opts3a, OptsCom3>(false)71 assertType.assignable<typeof opts1, OptsCom3>(false)72 assertType.notAssignable<typeof opts1, OptsCom3>()73 assertType.assignable<typeof opts3b, OptsCom3>()74 assertType.notAssignable<typeof opts3b, OptsCom3>(false)75 assertType.assignable<typeof opts2, OptsCom3>(false)76 assertType.notAssignable<typeof opts2, OptsCom3>()77 type R1 = typeof r178 type R2 = typeof r279 type R3a = typeof r3a80 type R3b = typeof r3b81 type CR1 = CommandReturn<Commands, 'com1'>82 type CR2 = CommandReturn<Commands, 'com2'>83 type CR3 = CommandReturn<Commands, 'com3'>84 assertType.equal<R1, CR1>()85 assertType.notEqual<R1, CR1>(false)86 assertType.equal<R2, CR2>()87 assertType.notEqual<R2, CR2>(false)88 assertType.equal<R3a, CR3>()89 assertType.notEqual<R3a, CR3>(false)90 assertType.equal<R3b, CR3>()91 assertType.notEqual<R3b, CR3>(false)92 const err = ERR('test')93 const ok_num = OK(3)94 const ok_str = OK('str')95 const ok_obj1 = OK({ x: 100 })96 const ok_obj2 = OK({ x: 'string' })97 expectType<ThenArg<R1>>(err)98 expectType<ThenArg<R1>>(ok_num)99 assertType.equal<R1, Promise<Result<number>>>()100 assertType.notEqual<R1, Promise<Result<number>>>(false)101 assertType.equal<R1, Promise<Result<string>>>(false)102 assertType.notEqual<R1, Promise<Result<string>>>()103 assertType.assignable<typeof ok_num, ThenArg<R1>>()104 assertType.notAssignable<typeof ok_num, ThenArg<R1>>(false)105 assertType.assignable<typeof err, ThenArg<R1>>()106 assertType.notAssignable<typeof err, ThenArg<R1>>(false)107 assertType.assignable<typeof ok_str, ThenArg<R1>>(false)108 assertType.notAssignable<typeof ok_str, ThenArg<R1>>()109 expectType<ThenArg<R2>>(err)110 expectType<ThenArg<R2>>(ok_obj1)111 assertType.equal<R2, Promise<Result<{ x: number }>>>()112 assertType.notEqual<R2, Promise<Result<{ x: number }>>>(false)113 assertType.equal<R2, Promise<Result<{ x: string }>>>(false)114 assertType.notEqual<R2, Promise<Result<{ x: string }>>>()115 assertType.assignable<typeof ok_obj1, ThenArg<R2>>()116 assertType.notAssignable<typeof ok_obj1, ThenArg<R2>>(false)117 assertType.assignable<typeof ok_obj2, ThenArg<R2>>(false)118 assertType.notAssignable<typeof ok_obj2, ThenArg<R2>>()119 assertType.assignable<typeof ok_num, ThenArg<R2>>(false)120 assertType.notAssignable<typeof ok_num, ThenArg<R2>>()121 assertType.assignable<typeof err, ThenArg<R2>>()122 assertType.notAssignable<typeof err, ThenArg<R2>>(false)123 expectType<ThenArg<R3a>>(err)124 expectType<ThenArg<R3a>>(ok_str)125 expectType<ThenArg<R3b>>(err)126 expectType<ThenArg<R3b>>(ok_str)127 assertType.equal<R3a, R3b>()128 assertType.notEqual<R3a, R3b>(false)129 assertType.equal<R3a, Promise<Result<string>>>()130 assertType.notEqual<R3a, Promise<Result<string>>>(false)131 assertType.equal<R3a, Promise<Result<number>>>(false)132 assertType.notEqual<R3a, Promise<Result<number>>>()133 assertType.assignable<typeof ok_str, ThenArg<R3a>>()134 assertType.notAssignable<typeof ok_str, ThenArg<R3a>>(false)135 assertType.assignable<typeof err, ThenArg<R3a>>()136 assertType.notAssignable<typeof err, ThenArg<R3a>>(false)137 assertType.assignable<typeof ok_obj1, ThenArg<R3a>>(false)138 assertType.notAssignable<typeof ok_obj1, ThenArg<R3a>>()139 })140 test('handlers and server', async () => {141 const handlers_ok = defineHandlers<Commands>({142 com1: async (_, opts) => {143 opts.a144 opts.b145 return OK(2)146 },147 com2: async (_, _opts) => {148 return OK({ x: 100 })149 },150 com3: async (_, opts) => {151 opts.a152 opts.b153 return OK('str')154 },155 })156 const r1ok = await handlers_ok({}, { $cmd: 'com1', a: 0, b: '' })157 expect(r1ok.ok).toBe(true)158 expect(r1ok.value).toBe(2)159 const r2ok = await handlers_ok({}, { $cmd: 'com2' })160 expect(r2ok.ok).toBe(true)161 expect(r2ok.value).toEqual({ x: 100 })162 const r3ok = await handlers_ok({}, { $cmd: 'com3', a: 0 })163 expect(r3ok.ok).toBe(true)164 expect(r3ok.value).toBe('str')165 const r4ok = await handlers_ok({}, { $cmd: 'com4' } as any)166 expect(r4ok.ok).toBe(false)167 expect(r4ok.error).not.toBeUndefined()168 if (!r4ok.ok) {169 expect(r4ok.error.message).toBe('unexpected $cmd: com4')170 }171 expect(r4ok.error)172 const handlers_err = defineHandlers<Commands>({173 com1: async (_, _opts) => {174 return ERR('test')175 },176 com2: async (_, _opts) => {177 return ERR(new Error())178 },179 com3: async (_, _opts) => {180 return ERR(100)181 },182 })183 const server: Server<Commands> = {184 handle: () => {},185 handleOnce: () => {},186 removeHandler: () => {},187 } as any188 server.handle(handlers_ok)189 server.handle(handlers_err)190 server.handleOnce(handlers_ok)191 server.handleOnce(handlers_err)192 server.removeHandler()193 server.removeHandler()194 })...
cardFormula.js
Source:cardFormula.js
...47 console.log('compare cards: %s !> %s', cards, comp);48 cardFormula.isCardsGreater(_cards, _compCards, true, true).should.be.false;49 });50 };51 assertType(52 ['XY'],53 consts.card.handTypes.ROCKET);54 assertType(55 ['AAAA', 'JJJJ', '2222', '0000', '5555'],56 consts.card.handTypes.BOMB);57 assertType(58 ['3', '4', '8', '9', 'Q'],59 consts.card.handTypes.SOLO);60 assertType(61 ['33', '44', '88', '99', 'QQ', '22'],62 consts.card.handTypes.PAIR);63 assertType(64 ['34567', '0JQKA', '3456789'],65 consts.card.handTypes.STRAIGHT);66 assertType(67 ['334455', '445566', '77889900', '9900JJ', 'QQKKAA'],68 consts.card.handTypes.CONSECUTIVE_PAIRS);69 assertType(70 ['333', '444', '888', '999', 'QQQ', '222'],71 consts.card.handTypes.TRIO);72 assertType(73 ['3334', '3444', '4888', '9990', 'JQQQ', 'A222'],74 consts.card.handTypes.TRIO_SOLO);75 assertType(76 ['33344', '33444', '44888', '99900', 'JJQQQ', 'AA222'],77 consts.card.handTypes.TRIO_PAIR);78 assertType(79 ['333444', '444555', '777888', '999000', 'JJJQQQ', 'KKKAAA'],80 consts.card.handTypes.AIRPLANE);81 assertType(82 ['333444XY', '4445552X', '888999JA', '999000KK', '3QQQKKKA'],83 consts.card.handTypes.AIRPLANE_SOLO);84 assertType(85 ['3334445566', '3344455566', '4488899922', '999000AA22', '00JJJQQQKK', '00KKKAAA22'],86 consts.card.handTypes.AIRPLANE_PAIR);87 assertType(88 ['333345', '334444', '8888KX', '999922', '5QQQQK', '2222XY'],89 consts.card.handTypes.SPACE_SHUTTLE_SOLO);90 assertType(91 ['33334455', '33444466', '33448888', '999900KK', 'JJQQQQ22', '55AA2222'],92 consts.card.handTypes.SPACE_SHUTTLE_PAIR);93 assertInvalid([94 '2345', '234', '345', 'A23', 'KKAA22', '23444', '3AAA222X', 'AAA222',95 'QKA2X'96 ]);97 assertGreater([98 ['2', 'A'],99 ['Y', 'X'],100 ['Y', 'J'],101 ['44', '33'],102 ['22', 'AA'],103 ['45678', '34567'],104 ['QQKKAA', '445566'],...
assert.js
Source:assert.js
...42 * keywordParameters: {optional: boolean}43 */44 45 /* examples: 46 * dojo.lang.assertType("foo", String);47 * dojo.lang.assertType(12345, Number);48 * dojo.lang.assertType(false, Boolean);49 * dojo.lang.assertType([6, 8], Array);50 * dojo.lang.assertType(dojo.lang.assertType, Function);51 * dojo.lang.assertType({foo: "bar"}, Object);52 * dojo.lang.assertType(new Date(), Date);53 * dojo.lang.assertType(null, Array, {optional: true});54 * throws: Throws an Error if 'value' is not of type 'type'.55 */56 if (dojo.lang.isString(keywordParameters)) {57 dojo.deprecated('dojo.lang.assertType(value, type, "message")', 'use dojo.lang.assertType(value, type) instead', "0.5");58 }59 if(!dojo.lang.isOfType(value, type, keywordParameters)){60 if(!dojo.lang.assertType._errorMessage){61 dojo.lang.assertType._errorMessage = "Type mismatch: dojo.lang.assertType() failed.";62 }63 dojo.lang.assert(false, dojo.lang.assertType._errorMessage);64 }65}66dojo.lang.assertValidKeywords = function(/* object */ object, /* array */ expectedProperties, /* string? */ message){67 /* summary: 68 * Throws an exception 'object' has any properties other than the 'expectedProperties'.69 * description: 70 * Given an anonymous object and a list of expected property names, this71 * method check to make sure the object does not have any properties72 * that aren't on the list of expected properties, and throws an Error73 * if there are unexpected properties. This is useful for doing error74 * checking on keyword arguments, to make sure there aren't typos.75 * object: An anonymous object....
afirmar.test.js
Source:afirmar.test.js
...33 expect(() => assert("abc", /^[a-z]$/)).toThrow();34 expect(() => assert("abc", /^xxx$/)).toThrow();35 });36 });37 describe("assertType()", () => {38 it("works with basic types", () => {39 assertType(true, "boolean");40 assertType(false, "boolean");41 expect(() => assertType(true, "string")).toThrow();42 expect(() => assertType(true, "number")).toThrow();43 expect(() => assertType(true, "array")).toThrow();44 expect(() => assertType(true, "object")).toThrow();45 assertType("", "string");46 assertType("abc", "string");47 expect(() => assertType("abc", "boolean")).toThrow();48 expect(() => assertType("abc", "number")).toThrow();49 expect(() => assertType("abc", "array")).toThrow();50 expect(() => assertType("abc", "object")).toThrow();51 assertType(0, "number");52 assertType(1, "number");53 expect(() => assertType(1, "boolean")).toThrow();54 expect(() => assertType(1, "string")).toThrow();55 expect(() => assertType(1, "array")).toThrow();56 expect(() => assertType(1, "object")).toThrow();57 assertType([], "array");58 assertType(["a", "b"], "array");59 expect(() => assertType([], "boolean")).toThrow();60 expect(() => assertType([], "string")).toThrow();61 expect(() => assertType([], "number")).toThrow();62 expect(() => assertType([], "object")).toThrow();63 assertType({}, "object");64 assertType({ a: "b" }, "object");65 expect(() => assertType({}, "boolean")).toThrow();66 expect(() => assertType({}, "string")).toThrow();67 expect(() => assertType({}, "number")).toThrow();68 expect(() => assertType({}, "array")).toThrow();69 });70 });...
test_assert.js
Source:test_assert.js
...20 }21 jum.assertTrue("404", caught404);22 // dojo.log.debug("leaving test_lang_assert()");23}24function test_lang_assertType() {25 dojo.lang.assertType("foo", String, "410");26 dojo.lang.assertType(12345, Number, "411");27 dojo.lang.assertType(false, Boolean, "412");28 dojo.lang.assertType([6, 8], Array, "413");29 dojo.lang.assertType(dojo.lang.assertType, Function, "414");30 dojo.lang.assertType({foo: "bar"}, Object, "415");31 dojo.lang.assertType(new Date(), Date, "416");32 dojo.lang.assertType(new Error(), Error, "417");33 dojo.lang.assertType([6, 8], ["array", "optional"], "418");34 dojo.lang.assertType(null, ["array", "optional"], "419");35 var caught430 = false;36 try {37 dojo.lang.assertType(12345, Boolean, "430");38 } catch (e) {39 caught430 = true;40 }41 jum.assertTrue("430", caught430);42 var caught431 = false;43 try {44 dojo.lang.assertType("foo", [Number, Boolean, Object], "431");45 } catch (e) {46 caught431 = true;47 }48 jum.assertTrue("431", caught431);49 // dojo.log.debug("leaving test_lang_assertType()");50}51function test_lang_assertValidKeywords() {52 dojo.lang.assertValidKeywords({a: 1, b: 2}, ["a", "b"], "440");53 dojo.lang.assertValidKeywords({a: 1, b: 2}, ["a", "b", "c"], "441");54 dojo.lang.assertValidKeywords({foo: "iggy"}, ["foo"], "442");55 dojo.lang.assertValidKeywords({foo: "iggy"}, ["foo", "bar"], "443");56 dojo.lang.assertValidKeywords({foo: "iggy"}, {foo: null, bar: null}, "444");57 var caught450 = false;58 try {59 dojo.lang.assertValidKeywords({a: 1, b: 2, c: 3}, ["a", "b"], "450");60 } catch (e) {61 caught450 = true;62 }63 jum.assertTrue("450", caught450);...
Using AI Code Generation
1const { assertType } = require('@playwright/test');2const { assertType } = require('@playwright/test');3const { assertType } = require('@playwright/test');4const { assertType } = require('@playwright/test');5const { assertType } = require('@playwright/test');6const { assertType } = require('@playwright/test');7const { assertType } = require('@playwright/test');8const { assertType } = require('@playwright/test');9const { assertType } = require('@playwright/test');10const { assertType } = require('@playwright/test');11const { assertType } = require('@playwright/test');12const { assertType } = require('@playwright/test');13const { assertType } = require('@playwright/test');14const { assertType } = require('@playwright/test');15const { assertType } = require('@playwright/test');16const { assertType } = require('@playwright/test');17const { assertType } = require('@playwright/test');18const { assertType } = require('@playwright/test');19const { assertType } = require('@playwright/test');20test('My test', async ({ page }) => {21 const page1 = page;22 assertType(page1,
Using AI Code Generation
1const { assertType } = require('@playwright/test');2assertType(1, 'number');3assertType('hello', 'string');4assertType(true, 'boolean');5assertType(null, 'null');6assertType(undefined, 'undefined');7assertType({}, 'object');8assertType([], 'array');9assertType(new Map(), 'map');10assertType(new Set(), 'set');11assertType(new Date(), 'date');12assertType(new Error(), 'error');13assertType(new RegExp(), 'regexp');14assertType(new Promise(() => {}), 'promise');15assertType(document, 'html');16assertType(document.body, 'html');17assertType(document.createElement('div'), 'html');18assertType(document.createElement('div'), 'element');19assertType(document.createElement('div'), 'node');20assertType(document.createElement('div'), 'text');21assertType(document.createElement('div'), 'comment');22assertType(document.createElement('div'), 'document');23assertType(document.createElement('div'), 'shadowroot');24assertType(document.createElement('div'), 'documentfragment');25assertType(document.createElement('div'), 'xpathresult');26assertType(document.createElement('div'), 'attr');27assertType(document.createElement('div'), 'characterdata');28assertType(document.createElement('div'), 'event');29assertType(document.createElement('div'), 'shadowrootmode');30assertType(document.createElement('div'), 'shadowroottype');31assertType(document.createElement('div'), 'xmlhttprequest');32assertType(document.createElement('div'), 'xmlhttprequestupload');33assertType(document.createElement('div'), 'xmlserializer');34assertType(document.createElement('div'), 'xpathexpression');35assertType(document.createElement('div'), 'xpathnsresolver');36assertType(document.createElement('div'), 'xpathresult');37assertType(document.createElement('div'), 'window');38assertType(document.createElement('div'), 'global');39assertType(document.createElement('div'), 'console');40assertType(document.createElement('div'), 'location');41assertType(document.createElement('div'), 'history');42assertType(document.createElement('div'), 'customevent');43assertType(document.createElement('div'), 'storage');44assertType(document.createElement('div'), 'storagetype');45assertType(document.createElement('div'), 'sessionstorage');46assertType(document.createElement('div'), 'localstorage');47assertType(document.createElement('div'), 'windoworworkerglobalscope');48assertType(document.createElement('div'), 'abstractworker');49assertType(document.createElement('div'), 'dedicatedworkerglobalscope');50assertType(document.createElement('div
Using AI Code Generation
1const assertType = require('@playwright/test').assertType;2assertType(1, 'number');3assertType('string', 'string');4assertType(true, 'boolean');5assertType(null, 'object');6assertType(undefined, 'undefined');7assertType({}, 'object');8assertType([], 'object');9assertType(() => {}, 'function');10assertType(new Map(), 'object');11assertType(new Set(), 'object');12assertType(new Date(), 'object');13assertType(new Error(), 'object');14assertType(new RegExp(), 'object');15assertType(new Int8Array(), 'object');16assertType(new Uint8Array(), 'object');17assertType(new Uint8ClampedArray(), 'object');18assertType(new Int16Array(), 'object');19assertType(new Uint16Array(), 'object');20assertType(new Int32Array(), 'object');21assertType(new Uint32Array(), 'object');22assertType(new Float32Array(), 'object');23assertType(new Float64Array(), 'object');24assertType(new BigInt64Array(), 'object');25assertType(new BigUint64Array(), 'object');26assertType(new ArrayBuffer(), 'object');27assertType(new SharedArrayBuffer(), 'object');28assertType(new DataView(new ArrayBuffer()), 'object');29assertType(new WeakMap(), 'object');30assertType(new WeakSet(), 'object');31assertType(new Proxy({}, {}), 'object');32assertType(document, 'object');33assertType(window, 'object');34assertType(document.body, 'object');35assertType(document.body.style, 'object');36assertType(document.body.style.display, 'string');37assertType(document.body.style.display = 'none', 'string');38assertType(document.body.style.display = 'none', 'undefined');39assertType(document.body.style.display = 'none', 'object');40assertType(document.body.style.display = 'none', 'boolean');41assertType(document.body.style.display = 'none', 'number');42assertType(document.body.style.display = 'none', 'function');43assertType(document.body.style.display = 'none', 'symbol');44assertType(Symbol('foo'), 'symbol');45assertType(Symbol.iterator, 'symbol');46assertType(Symbol.toStringTag, 'symbol');47assertType(Symbol.hasInstance, 'symbol');48assertType(Symbol.isConcatSpreadable, 'symbol');49assertType(Symbol.unscopables, 'symbol');50assertType(Symbol.species, 'symbol');51assertType(Symbol.match, 'symbol');52assertType(Symbol.replace, 'symbol');53assertType(Symbol.search,
Using AI Code Generation
1const assertType = require('playwright/lib/internal/stackTraces').assertType;2const assert = require('playwright/lib/internal/stackTraces').assert;3const assertType = require('playwright/lib/internal/stackTraces').assertType;4const assert = require('playwright/lib/internal/stackTraces').assert;5const { test, expect } = require('@playwright/test');6test('example test', async ({ page }) => {7 const title = page.locator('text=Get started');8 await expect(title).toBeVisible();
Using AI Code Generation
1const { assertType } = require('@playwright/test');2assertType('string', 'hello');3assertType('number', 5);4assertType('boolean', true);5assertType('object', {});6assertType('function', () => {});7assertType('undefined', undefined);8assertType('null', null);9assertType('array', []);10assertType('regexp', /./);11assertType('symbol', Symbol('foo'));12assertType('bigint', 42n);13assertType('map', new Map());14assertType('set', new Set());15assertType('weakmap', new WeakMap());16assertType('weakset', new WeakSet());17assertType('date', new Date());18assertType('error', new Error());19assertType('promise', new Promise(() => {}));20assertType('int8array', new Int8Array());21assertType('uint8array', new Uint8Array());22assertType('uint8clampedarray', new Uint8ClampedArray());23assertType('int16array', new Int16Array());24assertType('uint16array', new Uint16Array());25assertType('int32array', new Int32Array());26assertType('uint32array', new Uint32Array());27assertType('float32array', new Float32Array());28assertType('float64array', new Float64Array());29assertType('arraybuffer', new ArrayBuffer());30assertType('dataview', new DataVi
Using AI Code Generation
1const { assertType } = require('@playwright/test');2assertType('string', 'Hello World!');3const { expect } = require('@playwright/test');4expect('Hello World!').toBe('Hello World!');5const { expect } = require('@playwright/test');6const { test, expect } = require('@playwright/test');7test('My test', async ({ page }) => {8 const userAgent = await page.textContent('div');9 expect(userAgent).toContain('Firefox');10});
Using AI Code Generation
1const assert = require('assert');2const { assertType } = require('playwright/lib/internal/utils');3const { BrowserContext } = require('playwright/lib/server/browserContext');4const { BrowserType } = require('playwright/lib/server/browserType');5assertType(BrowserType, 'BrowserType');6assertType(BrowserContext, 'BrowserContext');7assertType(BrowserType, 'BrowserContext');8assertType(BrowserContext, 'BrowserType');9 at assertType (internal/utils.js:32:11)10 at Object.<anonymous> (test.js:10:1)11 at Module._compile (internal/modules/cjs/loader.js:1137:30)12 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)13 at Module.load (internal/modules/cjs/loader.js:985:32)14 at Function.Module._load (internal/modules/cjs/loader.js:878:14)15 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)16 at internal/main/run_main_module.js:17:47 {17}
Using AI Code Generation
1const { assertType } = require('@playwright/test/lib/utils').internal;2assertType('string', 'foo');3const { assertType } = require('@playwright/test/lib/utils').internal;4assertType('string', 'foo');5const { assertType } = require('@playwright/test/lib/utils').internal;6assertType('string', 'foo');7const { assertType } = require('@playwright/test/lib/utils').internal;8assertType('string', 'foo');9const { assertType } = require('@playwright/test/lib/utils').internal;10assertType('string', 'foo');11const { assertType } = require('@playwright/test/lib/utils').internal;12assertType('string', 'foo');13const { assertType } = require('@playwright/test/lib/utils').internal;14assertType('string', 'foo');15const { assertType } = require('@playwright/test/lib/utils').internal;16assertType('string', 'foo');17const { assertType } = require('@playwright/test/lib/utils').internal;18assertType('string', 'foo');19const { assertType } = require('@playwright/test/lib/utils').internal;20assertType('string', 'foo');21const { assertType } = require('@playwright/test/lib/utils').internal;
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.
Get 100 minutes of automation test minutes FREE!!