Best JavaScript code snippet using playwright-internal
prop-types-test.js
Source:prop-types-test.js
...203 })204 instance = MyObject.create()205 })206 ;['foo', 'bar'].forEach((prop) => {207 it(`should call validateProperty() for ${prop}`, function () {208 expect(helpers.validateProperty).to.have.been.calledWith(instance, prop)209 })210 })211 })212 describe('propTypes defined with validations present on Ember.Component', function () {213 let instance214 beforeEach(function () {215 sandbox.spy(helpers, 'validateProperty')216 const MyComponent = Component.extend(PropTypesMixin, {217 getDefaultProps () {218 return {219 foo: '!foo',220 bar: 647221 }222 }223 })224 instance = createComponent(MyComponent)225 })226 it('should set defaults for each property', function () {227 expect(instance.get('foo')).to.equal('!foo')228 expect(instance.get('bar')).to.equal(647)229 })230 })231 describe('propTypes defined with validations present on Ember.Component and Ember.Mixin', function () {232 let instance233 beforeEach(function () {234 sandbox.spy(helpers, 'validateProperty')235 const MyMixin = Mixin.create(PropTypesMixin, {236 propTypes: {237 baz: PropTypes.string,238 quux: PropTypes.number239 }240 })241 const MyComponent = Component.extend(PropTypesMixin, MyMixin, {242 propTypes: {243 foo: PropTypes.string,244 bar: PropTypes.number245 }246 })247 instance = createComponent(MyComponent)248 })249 ;['foo', 'bar', 'baz', 'quux'].forEach((prop) => {250 it(`should call validateProperty() for ${prop}`, function () {251 expect(helpers.validateProperty).to.have.been.calledWith(instance, prop)252 })253 })254 })255 describe('propTypes defined with defaults present on Ember.Object', function () {256 let instance257 beforeEach(function () {258 sandbox.spy(helpers, 'validateProperty')259 const MyObject = EmberObject.extend(PropTypesMixin, {260 getDefaultProps () {261 return {262 foo: '!foo',263 bar: 647264 }265 }266 })267 instance = MyObject.create()268 })269 it('should set defaults for each property', function () {270 expect(instance.get('foo')).to.equal('!foo')271 expect(instance.get('bar')).to.equal(647)272 })273 })274 describe('propTypes defined with defaults present on Ember.Component', function () {275 let instance276 beforeEach(function () {277 sandbox.spy(helpers, 'validateProperty')278 const MyComponent = Component.extend(PropTypesMixin, {279 propTypes: {280 foo: PropTypes.string,281 bar: PropTypes.number282 },283 getDefaultProps () {284 return {285 foo: '!foo',286 bar: 647287 }288 }289 })290 instance = createComponent(MyComponent)291 })292 ;['foo', 'bar'].forEach((prop) => {293 it(`should call validateProperty() for ${prop}`, function () {294 expect(helpers.validateProperty).to.have.been.calledWith(instance, prop)295 })296 })297 it('should set defaults for each property', function () {298 expect(instance.get('foo')).to.equal('!foo')299 expect(instance.get('bar')).to.equal(647)300 })301 })302 describe('propTypes defined with validations and defaults present on Ember.Object', function () {303 let instance304 beforeEach(function () {305 sandbox.spy(helpers, 'validateProperty')306 const Object = EmberObject.extend(PropTypesMixin, {307 propTypes: {308 foo: PropTypes.string,309 bar: PropTypes.number310 },311 getDefaultProps () {312 return {313 foo: '!foo',314 bar: 647315 }316 }317 })318 instance = Object.create()319 })320 ;['foo', 'bar'].forEach((prop) => {321 it(`should call validateProperty() for ${prop}`, function () {322 expect(helpers.validateProperty).to.have.been.calledWith(instance, prop)323 })324 })325 it('should set defaults for each property', function () {326 expect(instance.get('foo')).to.equal('!foo')327 expect(instance.get('bar')).to.equal(647)328 })329 })330 describe('propTypes defined with validations and defaults present on Ember.Component', function () {331 let instance332 beforeEach(function () {333 sandbox.spy(helpers, 'validateProperty')334 const MyComponent = Component.extend(PropTypesMixin, {335 propTypes: {336 foo: PropTypes.string,337 bar: PropTypes.number338 },339 getDefaultProps () {340 return {341 foo: '!foo',342 bar: 647343 }344 }345 })346 instance = createComponent(MyComponent)347 })348 ;['foo', 'bar'].forEach((prop) => {349 it(`should call validateProperty() for ${prop}`, function () {350 expect(helpers.validateProperty).to.have.been.calledWith(instance, prop)351 })352 })353 it('should set defaults for each property', function () {354 expect(instance.get('foo')).to.equal('!foo')355 expect(instance.get('bar')).to.equal(647)356 })357 })358 describe('propTypes defined with validations and defaults present on Ember.Component and Ember.Mixin', function () {359 let instance360 beforeEach(function () {361 sandbox.spy(helpers, 'validateProperty')362 const MyMixin = Mixin.create(PropTypesMixin, {363 propTypes: {364 baz: PropTypes.string,365 quux: PropTypes.number366 },367 getDefaultProps () {368 return {369 foo: 'INVALID',370 baz: '!baz',371 quux: '!quux'372 }373 }374 })375 const MyComponent = Component.extend(PropTypesMixin, MyMixin, {376 propTypes: {377 foo: PropTypes.string,378 bar: PropTypes.number379 },380 getDefaultProps () {381 return {382 foo: '!foo',383 bar: 647384 }385 }386 })387 instance = createComponent(MyComponent)388 })389 ;['foo', 'bar', 'baz', 'quux'].forEach((prop) => {390 it(`should call validateProperty() for ${prop}`, function () {391 expect(helpers.validateProperty).to.have.been.calledWith(instance, prop)392 })393 })394 it('should set defaults for each property', function () {395 expect(instance.get('foo')).to.equal('!foo')396 expect(instance.get('bar')).to.equal(647)397 expect(instance.get('baz')).to.equal('!baz')398 expect(instance.get('quux')).to.equal('!quux')399 })400 })401 describe('applies defaults when user set value is undefined', function () {402 let instance403 beforeEach(function () {404 sandbox.spy(helpers, 'validateProperty')...
validate-property.spec.js
Source:validate-property.spec.js
...66 });67 });68 it('accept strings', () => {69 expect(() =>70 validateProperty('Thing', 'prop', 'I am Tracy Beaker'),71 ).not.toThrow();72 });73 it('not accept booleans', () => {74 expect(() =>75 validateProperty('Thing', 'prop', true),76 ).toThrow(/Must be a string/);77 expect(() =>78 validateProperty('Thing', 'prop', false),79 ).toThrow(/Must be a string/);80 });81 it('not accept floats', () => {82 expect(() =>83 validateProperty('Thing', 'prop', 1.34),84 ).toThrow(/Must be a string/);85 });86 it('not accept integers', () => {87 expect(() =>88 validateProperty('Thing', 'prop', 134),89 ).toThrow(/Must be a string/);90 });91 it('apply string patterns', () => {92 expect(() =>93 validateProperty('Thing', 'prop', 'I am zebbedee'),94 ).toThrow('Must match pattern /^[^z]+$/');95 expect(() =>96 validateProperty('Thing', 'shortprop', '13 characters'),97 ).toThrow(98 'Must match pattern /^.{2,4}$/ and be no more than 4 characters',99 );100 });101 }102 });103 });104 describe('validating booleans', () => {105 let validateProperty;106 beforeEach(() => {107 validateProperty = getValidator({108 name: 'Thing',109 properties: {110 prop: {111 type: 'Boolean',112 },113 },114 });115 });116 it('not accept strings', () => {117 expect(() =>118 validateProperty('Thing', 'prop', 'I am Tracy Beaker'),119 ).toThrow(/Must be a Boolean/);120 });121 it('accept booleans', () => {122 expect(() => validateProperty('Thing', 'prop', true)).not.toThrow();123 expect(() =>124 validateProperty('Thing', 'prop', false),125 ).not.toThrow();126 });127 it('not accept floats', () => {128 expect(() => validateProperty('Thing', 'prop', 1.34)).toThrow(129 /Must be a Boolean/,130 );131 });132 it('not accept integers', () => {133 expect(() => validateProperty('Thing', 'prop', 134)).toThrow(134 /Must be a Boolean/,135 );136 });137 });138 describe('validating floats', () => {139 let validateProperty;140 beforeEach(() => {141 validateProperty = getValidator({142 name: 'Thing',143 properties: {144 prop: {145 type: 'Float',146 },147 },148 });149 });150 it('not accept strings', () => {151 expect(() =>152 validateProperty('Thing', 'prop', 'I am Tracy Beaker'),153 ).toThrow(/Must be a finite floating point number/);154 });155 it('not accept booleans', () => {156 expect(() => validateProperty('Thing', 'prop', true)).toThrow(157 /Must be a finite floating point number/,158 );159 expect(() => validateProperty('Thing', 'prop', false)).toThrow(160 /Must be a finite floating point number/,161 );162 });163 it('accept floats', () => {164 expect(() => validateProperty('Thing', 'prop', 1.34)).not.toThrow();165 });166 it('accept integers', () => {167 expect(() => validateProperty('Thing', 'prop', 134)).not.toThrow();168 });169 });170 describe('validating integers', () => {171 let validateProperty;172 beforeEach(() => {173 validateProperty = getValidator({174 name: 'Thing',175 properties: {176 prop: {177 type: 'Int',178 },179 },180 });181 });182 it('not accept strings', () => {183 expect(() =>184 validateProperty('Thing', 'prop', 'I am Tracy Beaker'),185 ).toThrow(/Must be a finite integer/);186 });187 it('not accept booleans', () => {188 expect(() => validateProperty('Thing', 'prop', true)).toThrow(189 /Must be a finite integer/,190 );191 expect(() => validateProperty('Thing', 'prop', false)).toThrow(192 /Must be a finite integer/,193 );194 });195 it('not accept floats', () => {196 expect(() => validateProperty('Thing', 'prop', 1.34)).toThrow(197 /Must be a finite integer/,198 );199 });200 it('accept integers', () => {201 expect(() => validateProperty('Thing', 'prop', 134)).not.toThrow();202 });203 });204 describe('validating enums', () => {205 let validateProperty;206 beforeEach(() => {207 const enums = {208 MyEnum: {209 options: { bear: 'grylls', ray: 'winstone' },210 },211 };212 validateProperty = getValidator(213 {214 name: 'Thing',215 properties: {216 prop: {217 type: 'MyEnum',218 },219 },220 },221 { enums },222 );223 });224 it('accept value defined in a mapping enum', () => {225 expect(() =>226 validateProperty('Thing', 'prop', 'bear'),227 ).not.toThrow();228 });229 it('not accept value not defined in a mapping enum', () => {230 expect(() => validateProperty('Thing', 'prop', 'ban')).toThrow(231 /Must be a valid enum/,232 );233 });234 });235 describe('validating relationships', () => {236 let validateProperty;237 beforeEach(() => {238 validateProperty = getValidator([239 {240 name: 'StartType',241 properties: {242 testRelationship: {243 type: 'EndType',244 direction: 'outgoing',245 relationship: 'HAS',246 hasMany: false,247 },248 testCypherRelationship: {249 type: 'EndType',250 cypher: 'ha',251 },252 },253 },254 {255 name: 'EndType',256 properties: {257 code: { pattern: 'LOWERCASE', type: 'String' },258 inverseTestRelationship: {259 type: 'StartType',260 direction: 'incoming',261 relationship: 'HAS',262 hasMany: false,263 },264 },265 },266 ]);267 });268 it('reject when related node code is invalid', () => {269 expect(() =>270 validateProperty('StartType', 'testRelationship', 'UPPERCASE'),271 ).toThrow(272 'Invalid value `UPPERCASE` for property `code` on type `EndType`: Must match pattern /^[a-z]+$/',273 );274 });275 it('reject when sending multiple codes and not is hasMany', () => {276 expect(() =>277 validateProperty('StartType', 'testRelationship', [278 'lowercase1',279 'lowercase2',280 ]),281 ).toThrow(/Can only have one testRelationship/);282 });283 it('reject when writing to cypher relationship', () => {284 expect(() =>285 validateProperty('StartType', 'testCypherRelationship', 'code'),286 ).toThrow(287 /Cannot write relationship `testCypherRelationship` - it is defined using a custom, read-only query/,288 );289 });290 it('accept when all is correct', () => {291 expect(() =>292 validateProperty('StartType', 'testRelationship', 'lowercase'),293 ).not.toThrow();294 });295 });296 describe('validating relationship properties', () => {297 let validateProperty;298 beforeEach(() => {299 const types = [300 {301 name: 'StartType',302 properties: {303 relAcceptProps: { type: 'RelationshipType' },304 relNotAcceptProps: {305 type: 'EndType',306 direction: 'outgoing',307 relationship: 'HAS_ENDTYPE',308 hasMany: true,309 },310 },311 },312 {313 name: 'EndType',314 properties: {315 code: { pattern: 'LOWERCASE', type: 'String' },316 isRelAcceptProps: {317 type: 'RelationshipType',318 },319 isRelNotAcceptProps: {320 relationship: 'HAS_ENDTYPE',321 type: 'StartType',322 direction: 'incoming',323 hasMany: true,324 },325 },326 },327 ];328 const relationshipTypes = [329 {330 name: 'RelationshipType',331 relationship: 'HAS',332 from: { type: 'StartType', hasMany: true },333 to: { type: 'EndType', hasMany: true },334 properties: {335 someString: { type: 'Word' },336 },337 },338 ];339 validateProperty = getValidator(types, { relationshipTypes });340 });341 it('reject when relationship node code is invalid', () => {342 expect(() =>343 validateProperty('StartType', 'relAcceptProps', {344 code: 'UPPERCASE',345 }),346 ).toThrow(347 'Invalid value `UPPERCASE` for property `code` on type `EndType`: Must match pattern /^[a-z]+$/',348 );349 });350 it('reject when relationship property is invalid', () => {351 expect(() =>352 validateProperty('StartType', 'relAcceptProps', {353 someString: 1234,354 }),355 ).toThrow(356 'Invalid value `1234` for property `someString` on type `RelationshipType`: Must be a string',357 );358 });359 it('not accept if not in schema', () => {360 expect(() =>361 validateProperty('StartType', 'relAcceptProps', {362 code: 'lowercase',363 notInSchema: 'a string',364 }),365 ).toThrow(366 /Invalid property `notInSchema` on type `RelationshipType`/,367 );368 });369 it('not accept property but code if the type does not accept relationship properties', () => {370 expect(() =>371 validateProperty('StartType', 'relNotAcceptProps', {372 code: 'lowercase',373 }),374 ).not.toThrow();375 expect(() =>376 validateProperty('StartType', 'relNotAcceptProps', {377 someString: 'some string',378 }),379 ).toThrow(380 /`relNotAcceptProps` does not accept relationship properties/,381 );382 });383 it('accept when all is correct', () => {384 expect(() =>385 validateProperty('StartType', 'relAcceptProps', {386 code: 'lowercase',387 someString: 'some string',388 }),389 ).not.toThrow();390 });391 });...
map.js
Source:map.js
1const NO_FRONT_DETECTED = "No front detected";2const propertyMap = [3 { signalK: "environment.outside.pressure.trend.tendency", src: (json) => validateProperty(json.trend.tendency) },4 { signalK: "environment.outside.pressure.trend.trend", src: (json) => validateProperty(json.trend.trend) },5 { signalK: "environment.outside.pressure.trend.severity", src: (json) => validateProperty(json.trend.severity) },6 { signalK: "environment.outside.pressure.trend.period", src: (json) => validateProperty(json.trend.period * 60) },7 { signalK: "environment.outside.pressure.trend.period.from", src: (json) => validateProperty(json.trend.from.meta.value) },8 { signalK: "environment.outside.pressure.trend.period.to", src: (json) => validateProperty(json.trend.to.meta.value) },9 10 { signalK: "environment.outside.pressure.prediction.pressureOnly", src: (json) => validateProperty(json.predictions.pressureOnly) },11 { signalK: "environment.outside.pressure.prediction.quadrant", src: (json) => validateProperty(json.predictions.quadrant) },12 { signalK: "environment.outside.pressure.prediction.season", src: (json) => validateProperty(json.predictions.season) },13 { signalK: "environment.outside.pressure.prediction.beaufort", src: (json) => validateProperty(json.predictions.beaufort.force) },14 { signalK: "environment.outside.pressure.prediction.beaufort.description", src: (json) => validateProperty(json.predictions.beaufort.description) },15 { signalK: "environment.outside.pressure.prediction.front.tendency", src: (json) => validateProperty(json.predictions.front.tendency, NO_FRONT_DETECTED) },16 { signalK: "environment.outside.pressure.prediction.front.prognose", src: (json) => validateProperty(json.predictions.front.prognose, NO_FRONT_DETECTED) },17 { signalK: "environment.outside.pressure.prediction.front.wind", src: (json) => validateProperty(json.predictions.front.wind, NO_FRONT_DETECTED) },18 { signalK: "environment.outside.pressure.system", src: (json) => validateProperty(json.system.name) },19 { signalK: "environment.outside.pressure.1hr", src: (json) => history(json, 1) },20 { signalK: "environment.outside.pressure.3hr", src: (json) => history(json, 3) },21 { signalK: "environment.outside.pressure.6hr", src: (json) => history(json, 6) },22 { signalK: "environment.outside.pressure.12hr", src: (json) => history(json, 12) },23 { signalK: "environment.outside.pressure.24hr", src: (json) => history(json, 24) },24 { signalK: "environment.outside.pressure.48hr", src: (json) => history(json, 48) }25]26/**27 * 28 * @param {Array<Object>} json barometer-trend (npm-package) JSON structure29 * @returns [{path: path, value: value}]30 */31function mapProperties(json) {32 const deltaUpdates = [];33 propertyMap.forEach((p) => {34 try {35 let value = (json !== null) ? p.src(json) : defaultPropertyValue;36 let deltaUpdate = buildDeltaPath(p.signalK, value);37 deltaUpdates.push(deltaUpdate);38 } catch {39 console.debug("Failed to map property: " + p.signalK);40 }41 });42 return deltaUpdates.length > 0 ? deltaUpdates : null;43}44const history = (json, hour) => { 45 let pressure = json.history.find((h) => h.hour === hour).pressure;46 return pressure !== null ? validateProperty(pressure.meta.value) : null;47}48const defaultPropertyValue = null;49function validateProperty(value, defaultValue = defaultPropertyValue) {50 return (value !== null || value !== undefined) ? value : defaultValue;51}52function buildDeltaPath(path, value) {53 return {54 path: path,55 value: value56 }57}58module.exports = {59 mapProperties...
validate-property-attribute.js
Source:validate-property-attribute.js
1"use strict";2System.register(["aurelia-framework", "../strategy/validation-strategy"], function (_export, _context) {3 "use strict";4 var inject, customAttribute, ValidationStrategy, _dec, _dec2, _class, ValidateProperty;5 6 return {7 setters: [function (_aureliaFramework) {8 inject = _aureliaFramework.inject;9 customAttribute = _aureliaFramework.customAttribute;10 }, function (_strategyValidationStrategy) {11 ValidationStrategy = _strategyValidationStrategy.ValidationStrategy;12 }],13 execute: function () {14 _export("ValidateProperty", ValidateProperty = (_dec = customAttribute('validate-property'), _dec2 = inject(Element, ValidationStrategy), _dec(_class = _dec2(_class = function () {15 function ValidateProperty(element, validationStrategy) {16 var _this = this;17 18 this._validationStateHandler = function (args) {19 if (args.isValid) {20 _this.validationStrategy.actionValidProperty(_this.element, _this.value);21 } else {22 _this.validationStrategy.actionInvalidProperty(_this.element, _this.value, args.error);23 }24 };25 this._validationPredicate = function (x) {26 return x.property == _this.value;27 };28 this.setupValidation = function () {29 _this._activeSubscription = _this.validationGroup.propertyStateChangedEvent.subscribe(_this._validationStateHandler, _this._validationPredicate);30 };31 this.element = element;32 this.validationStrategy = validationStrategy;33 }34 ValidateProperty.prototype._isWithinChildBinding = function _isWithinChildBinding(overrideContext) {35 return overrideContext["$index"] || overrideContext["$even"] || overrideContext["$odd"];36 };37 ValidateProperty.prototype.bind = function bind(binding, overrideContext) {38 this.bindingContext = overrideContext;39 };40 ValidateProperty.prototype.attached = function attached() {41 var _this2 = this;42 if (this._isWithinChildBinding(this.bindingContext)) {43 this.bindingContext = this.bindingContext.parentOverrideContext;44 }45 this.validationGroup = this.bindingContext.validationGroup;46 this.validationOptions = this.bindingContext.validationOptions || {};47 if (this.validationGroup) {48 this.setupValidation();49 this.validationGroup.getPropertyError(this.value).then(function (error) {50 if (error) {51 _this2.validationStrategy.actionInvalidProperty(_this2.element, _this2.value, error);52 }53 });54 }55 };56 ValidateProperty.prototype.detached = function detached() {57 if (this._activeSubscription) {58 this._activeSubscription();59 }60 };61 return ValidateProperty;62 }()) || _class) || _class));63 _export("ValidateProperty", ValidateProperty);64 }65 };...
validate.js
Source:validate.js
...5/**6 * Validate a property as being on an object, and optionally7 * of a given type.8 */9function validateProperty(object, name, typeName) {10 if (!object.hasOwnProperty(name)) {11 throw Error(`Missing property '${name}'`);12 }13 if (typeName !== void 0) {14 let valid = true;15 let value = object[name];16 switch (typeName) {17 case 'array':18 valid = Array.isArray(value);19 break;20 case 'object':21 valid = typeof value !== 'undefined';22 break;23 default:24 valid = typeof value === typeName;25 }26 if (!valid) {27 throw new Error(`Property '${name}' is not of type '${typeName}`);28 }29 }30}31/**32 * Validate an `Contents.IModel` object.33 */34function validateContentsModel(model) {35 validateProperty(model, 'name', 'string');36 validateProperty(model, 'path', 'string');37 validateProperty(model, 'type', 'string');38 validateProperty(model, 'created', 'string');39 validateProperty(model, 'last_modified', 'string');40 validateProperty(model, 'mimetype', 'object');41 validateProperty(model, 'content', 'object');42 validateProperty(model, 'format', 'object');43}44exports.validateContentsModel = validateContentsModel;45/**46 * Validate an `Contents.ICheckpointModel` object.47 */48function validateCheckpointModel(model) {49 validateProperty(model, 'id', 'string');50 validateProperty(model, 'last_modified', 'string');51}...
accomodation.server.model.js
Source:accomodation.server.model.js
1'use strict';2/**3 * Module dependencies.4 */5var mongoose = require('mongoose'),6 Schema = mongoose.Schema;7/**8 * A Validation function for properties9 */10var validateProperty = function(property) {11 return (!this.updated || property.length);12};13/**14 * Accomodation Schema15 */16var AccomodationSchema = new Schema({17 name: {18 type: String,19 trim: true,20 default: '',21 validate: [validateProperty, 'Please fill in accomodation name']22 },23 location: {24 type: String,25 trim: true,26 default: '',27 validate: [validateProperty, 'Please fill in accomodation location']28 },29 address: {30 type: String,31 trim: true32 },33 website: {34 type: String,35 trim: true,36 default: '',37 validate: [validateProperty, 'Please fill in the website address'],38 match: [/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/, 'Please fill a valid url']39 },40 img: {41 type: String,42 trim: true,43 default: '',44 validate: [validateProperty, 'Please fill in the image address'],45 match: [/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/, 'Please fill a valid url']46 },47 updated: {48 type: Date49 },50 created: {51 type: Date,52 default: Date.now53 }54});...
utils.test.js
Source:utils.test.js
1'use strict';2const { validateProperty } = require('./utils');3describe('utils', () => {4 test('expect validateProperty() to return correct value if not required', () => {5 let obj = {key: 'test'};6 expect(validateProperty(obj, 'key')).toEqual(obj.key);7 obj = {key: ''};8 expect(validateProperty(obj, 'key')).toEqual(obj.key);9 obj = {key: 1};10 expect(validateProperty(obj, 'key')).toEqual(obj.key);11 obj = {key: null};12 expect(validateProperty(obj, 'key')).toEqual(obj.key);13 obj = {key: undefined};14 expect(validateProperty(obj, 'key')).toBeNull();15 });16 test('expect validateProperty() to return correct value if required', () => {17 let obj = {key: 'test'};18 expect(validateProperty(obj, 'key', true)).toEqual(obj.key);19 obj = {key: ''};20 expect(() => { validateProperty(obj, 'key', true) }).toThrow();21 obj = {key: ' '};22 expect(() => { validateProperty(obj, 'key', true) }).toThrow();23 obj = {key: 1};24 expect(validateProperty(obj, 'key', true)).toEqual(obj.key);25 obj = {key: null};26 expect(() => { validateProperty(obj, 'key', true) }).toThrow();27 obj = {key: undefined};28 expect(() => { validateProperty(obj, 'key', true) }).toThrow();29 });...
star.js
Source:star.js
...12 let { address, star = {} } = body;13 let { dec, ra, story, mag, con } = star;14 this.address = address;15 this.star = star;16 this.star.dec = validateProperty(star, 'dec', true);17 this.star.ra = validateProperty(star, 'ra', true);18 this.star.story = this.validateStory(story, star);19 this.star.mag = validateProperty(star, 'mag');20 this.star.con = validateProperty(star, 'con');21 }22 validateStory(story, star) {23 return validateStringMaxLength(24 validateIsASCII(validateProperty(star, 'story', true)),25 MAX_STORY_BYTES26 );27 }28 encodeStory() {29 this.star.story = asciiToHex(this.star.story);30 }31 decodeStory() {32 this.star.storyDecoded = hexToAscii(this.star.story);33 }34}...
Using AI Code Generation
1const { chromium } = require('playwright');2const { validateProperty } = require('playwright/lib/server/dom.js');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await browser.close();8})();9const { chromium } = require('playwright');10const { validateAttribute } = require('playwright/lib/server/dom.js');11(async () => {12 const browser = await chromium.launch();13 const context = await browser.newContext();14 const page = await context.newPage();15 await browser.close();16})();17const { chromium } = require('playwright');18const { validateInnerText } = require('playwright/lib/server/dom.js');19(async () => {20 const browser = await chromium.launch();21 const context = await browser.newContext();22 const page = await context.newPage();23 const result = await validateInnerText(search
Using AI Code Generation
1const { validateProperty } = require('playwright/lib/server/frames');2const { Page } = require('playwright/lib/server/page');3const { ElementHandle } = require('playwright/lib/server/elementHandler');4const { JSHandle } = require('playwright/lib/server/jsHandle');5const page = new Page(null, null, null);6const elementHandle = new ElementHandle(page, null, null);7const jsHandle = new JSHandle(elementHandle, null, null);8const result = validateProperty(jsHandle, 'innerHTML');9console.log(result);10{11}
Using AI Code Generation
1const { validateProperty } = require('@playwright/test/lib/server/validateProperty');2const { expect } = require('@playwright/test');3const { test } = require('@playwright/test');4test('test', async ({ page }) => {5 const pageObject = page;6 const property = 'mainFrame';7 const expectedType = 'Frame';8 const actualType = await validateProperty(pageObject, property);9 expect(actualType).toBe(expectedType);10});11const { validateProperty } = require('@playwright/test/lib/server/validateProperty');12const { expect } = require('@playwright/test');13const { test } = require('@playwright/test');14test('test', async ({ page }) => {15 const pageObject = page;16 const property = 'mainFrame';17 const expectedType = 'Frame';18 const actualType = await validateProperty(pageObject, property);19 expect(actualType).toBe(expectedType);20});21const { validateProperty } = require('@playwright/test/lib/server/validateProperty');22const { expect } = require('@playwright/test');23const { test } = require('@playwright/test');24test('test', async ({ page }) => {25 const pageObject = page;26 const property = 'mainFrame';27 const expectedType = 'Frame';28 const actualType = await validateProperty(pageObject, property);29 expect(actualType).toBe(expectedType);30});31const { validateProperty } = require('@playwright/test/lib/server/validateProperty');32const { expect } = require('@playwright/test');33const { test } = require('@playwright/test');34test('test', async ({ page }) => {35 const pageObject = page;36 const property = 'mainFrame';37 const expectedType = 'Frame';38 const actualType = await validateProperty(pageObject, property);39 expect(actualType).toBe(expectedType);40});41const { validateProperty } = require('@playwright/test/lib/server/validateProperty');42const { expect } = require('@playwright/test');43const { test } = require('@playwright/test');44test('test', async ({ page }) => {45 const pageObject = page;46 const property = 'mainFrame';
Using AI Code Generation
1const { validateProperty } = require('playwright/lib/server/validateOptions');2const { expect } = require('chai');3const schema = {4 properties: {5 foo: {6 },7 bar: {8 },9 },10};11const { error } = validateProperty(schema, { foo: 'bar', bar: 15 });12expect(error).to.be.undefined;13const { error: error2 } = validateProperty(schema, { foo: 'b', bar: 5 });14expect(error2).to.be.an('error');15expect(error2.message).to.equal('bar: must be >= 10');16expect(error2.errors).to.deep.equal([17 {18 },19]);20const { error: error3 } = validateProperty(schema, { foo: 'b', bar: 25 });21expect(error3).to.be.an('error');22expect(error3.message).to.equal('bar: must be <= 20, foo: must NOT have fewer than 2 characters');23expect(error3.errors).to.deep.equal([24 {25 },26 {27 },28]);29const { validateProperty } = require('playwright/lib/server/validateOptions');30const { expect } = require('chai');31const schema = {32 properties: {33 foo: {34 },35 bar: {36 },37 },38};39const { error } = validateProperty(schema, { foo: 'bar', bar: 15 });40expect(error).to.be.undefined;41const { error: error2 } = validateProperty(schema, { foo: 'b', bar: 5 });42expect(error2).to.be.an('error');43expect(error2.message).to.equal('bar: must be >= 10');44expect(error
Using AI Code Generation
1const { validateProperty } = require('@playwright/test/lib/utils/validation');2const result = validateProperty('browserName', 'chromium');3console.log(result);4const { validateType } = require('@playwright/test/lib/utils/validation');5const result = validateType('browserName', 'chromium', 'string');6console.log(result);7const { validateOptional } = require('@playwright/test/lib/utils/validation');8const result = validateOptional('browserName', 'chromium', 'string');9console.log(result);10const { validateEnum } = require('@playwright/test/lib/utils/validation');11const result = validateEnum('browserName', 'chromium', ['chromium', 'firefox', 'webkit']);12console.log(result);13const { validateArray } = require('@playwright/test/lib/utils/validation');14const result = validateArray('browserName', 'chromium', 'string');15console.log(result);16const { validateObject } = require('@playwright/test/lib/utils/validation');17const result = validateObject('browserName', 'chromium', 'string');18console.log(result);19const { validateFunction } = require('@playwright/test/lib/utils/validation');20const result = validateFunction('browserName', 'chromium', 'string');21console.log(result);22const { validateRegExp } = require('@playwright/test/lib/utils/validation');23const result = validateRegExp('browserName', 'chromium', 'string');24console.log(result);25const { validateInstance } = require('@playwright/test/lib/utils/validation');26const result = validateInstance('browserName', 'chromium', 'string');27console.log(result);28const { validateBoolean } = require('@playwright/test/lib/utils/validation');29const result = validateBoolean('browserName', 'chromium', 'string');30console.log(result);31const { validateNumber } = require('@playwright/test/lib/utils
Using AI Code Generation
1const { validateProperty } = require('playwright/lib/server/dom.js');2const property = { name: 'test', type: 'string' };3const value = 'test';4const result = validateProperty(property, value);5console.log(result);6{ valid: true, reason: undefined }7const value = 1;8{ valid: false, reason: 'Expected string but got number' }9const { validateProperty } = require('playwright/lib/server/dom.js');10const property = { name: 'value', type: 'string' };11const value = 'test';12const result = validateProperty(property, value, document.querySelector('input'));13console.log(result);14{ valid: true, reason: undefined }15const value = 1;16{ valid: false, reason: 'Expected string but got number' }
Using AI Code Generation
1const { validateProperty } = require('@playwright/test');2const { expect } = require('@playwright/test');3test.describe('Validate Property of Playwright Internal API', () => {4 test('validateProperty', async ({ page }) => {5 const title = await page.title();6 const result = validateProperty(title, 'string');7 expect(result).toBe(true);8 });9});10 ✓ validateProperty (2s)11 1 passed (2s)12const { validateProperty } = require('@playwright/test');13const { expect } = require('@playwright/test');14test.describe('Validate Property of Playwright Internal API', () => {15 test('validateProperty', async ({ page }) => {16 const title = await page.title();17 const result = validateProperty(title, 'number');18 expect(result).toBe(true);19 });20});21 ✕ validateProperty (2s)22 11 | const result = validateProperty(title, 'number');23 12 | expect(result).toBe(true);24 > 13 | });25 14 | });26 at Object.<anonymous> (test.js:13:5)27 1 failed (2s)
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!!