Best JavaScript code snippet using fast-check-monorepo
docs.ts
Source:docs.ts  
1/**2 * @license3 * Copyright (c) 2015 The Polymer Project Authors. All rights reserved.4 * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt6 * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt7 * Code distributed by Google as part of the polymer project is also8 * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt9 */10'use strict';11import * as jsdoc from './jsdoc'12import * as dom5 from 'dom5'13import {14  FeatureDescriptor, FunctionDescriptor, PropertyDescriptor, Descriptor,15  ElementDescriptor, BehaviorsByName, EventDescriptor, BehaviorDescriptor16} from './descriptors'17/** Properties on element prototypes that are purely configuration. */18const ELEMENT_CONFIGURATION = [19  'attached',20  'attributeChanged',21  'beforeRegister',22  'configure',23  'constructor',24  'created',25  'detached',26  'enableCustomStyleProperties',27  'extends',28  'hostAttributes',29  'is',30  'listeners',31  'mixins',32  'properties',33  'ready',34  'registered'35];36/** Tags understood by the annotation process, to be removed during `clean`. */37const HANDLED_TAGS = [38  'param',39  'return',40  'type',41];42/**43 * Annotates Hydrolysis descriptors, processing any `desc` properties as JSDoc.44 *45 * You probably want to use a more specialized version of this, such as46 * `annotateElement`.47 *48 * Processed JSDoc values will be made available via the `jsdoc` property on a49 * descriptor node.50 *51 * @param {Object} descriptor The descriptor node to process.52 * @return {Object} The descriptor that was given.53 */54export function annotate(descriptor: Descriptor): Descriptor{55  if (!descriptor || descriptor.jsdoc) return descriptor;56  if (typeof descriptor.desc === 'string') {57    descriptor.jsdoc = jsdoc.parseJsdoc(descriptor.desc);58    // We want to present the normalized form of a descriptor.59    descriptor.jsdoc.orig = descriptor.desc;60    descriptor.desc       = descriptor.jsdoc.description;61  }62  return descriptor;63}64/**65 * Annotates @event, @hero, & @demo tags66 */67export function annotateElementHeader(descriptor: ElementDescriptor) {68  if (descriptor.events) {69    descriptor.events.forEach(function(event) {70      _annotateEvent(event);71    });72    descriptor.events.sort( function(a,b) {73      return a.name.localeCompare(b.name);74    });75  }76  descriptor.demos = [];77  if (descriptor.jsdoc && descriptor.jsdoc.tags) {78    descriptor.jsdoc.tags.forEach( function(tag) {79      switch(tag.tag) {80        case 'hero':81          descriptor.hero = tag.name || 'hero.png';82          break;83        case 'demo':84          descriptor.demos.push({85            desc: tag.description || 'demo',86            path: tag.name || 'demo/index.html'87          });88          break;89      }90    });91  }92}93function copyProperties(94    from:ElementDescriptor, to:ElementDescriptor,95    behaviorsByName:BehaviorsByName) {96  if (from.properties) {97    from.properties.forEach(function(fromProp){98      for (var toProp:PropertyDescriptor, i = 0;99           i < to.properties.length; i++) {100        toProp = to.properties[i];101        if (fromProp.name === toProp.name) {102          return;103        }104      }105      var newProp = {__fromBehavior: from.is};106      if (fromProp.__fromBehavior) {107        return;108      }109      Object.keys(fromProp).forEach(function(propertyField){110        newProp[propertyField] = fromProp[propertyField];111      });112      to.properties.push(<any>newProp);113    });114    from.events.forEach(function(fromEvent){115      for (var toEvent:EventDescriptor, i = 0; i < to.events.length; i++) {116        toEvent = to.events[i];117        if (fromEvent.name === toEvent.name) {118          return;119        }120      }121      if (fromEvent.__fromBehavior) {122        return;123      }124      var newEvent = {__fromBehavior: from.is};125      Object.keys(fromEvent).forEach(function(eventField){126        newEvent[eventField] = fromEvent[eventField];127      });128      to.events.push(newEvent);129    });130  }131  if (!from.behaviors) {132    return;133  }134  for (let i = from.behaviors.length - 1; i >= 0; i--) {135    // TODO: what's up with behaviors sometimes being a literal, and sometimes136    // being a descriptor object?137    const localBehavior: any = from.behaviors[i];138    var definedBehavior =139        behaviorsByName[localBehavior] || behaviorsByName[localBehavior.symbol];140    if (!definedBehavior) {141        console.warn("Behavior " + localBehavior + " not found when mixing " +142          "properties into " + to.is + "!");143        return;144    }145    copyProperties(definedBehavior, to, behaviorsByName);146  }147}148function mixinBehaviors(149    descriptor:ElementDescriptor, behaviorsByName: BehaviorsByName) {150  if (descriptor.behaviors) {151    for (let i = descriptor.behaviors.length - 1; i >= 0; i--) {152      const behavior = <string>descriptor.behaviors[i];153      if (!behaviorsByName[behavior]) {154        console.warn("Behavior " + behavior + " not found when mixing " +155          "properties into " + descriptor.is + "!");156        break;157      }158      var definedBehavior = behaviorsByName[<string>behavior];159      copyProperties(definedBehavior, descriptor, behaviorsByName);160    }161  }162}163/**164 * Annotates documentation found within a Hydrolysis element descriptor. Also165 * supports behaviors.166 *167 * If the element was processed via `hydrolize`, the element's documentation168 * will also be extracted via its <dom-module>.169 *170 * @param {Object} descriptor The element descriptor.171 * @return {Object} The descriptor that was given.172 */173export function annotateElement(174    descriptor: ElementDescriptor,175    behaviorsByName: BehaviorsByName): ElementDescriptor {176  if (!descriptor.desc && descriptor.type === 'element') {177    descriptor.desc = _findElementDocs(descriptor.is,178                                       descriptor.domModule,179                                       descriptor.scriptElement);180  }181  annotate(descriptor);182  // The `<dom-module>` is too low level for most needs, and it is _not_183  // serializable. So we drop it now that we've extracted all the useful bits184  // from it.185  // TODO: Don't worry about serializability here, provide an API to get JSON.186  delete descriptor.domModule;187  mixinBehaviors(descriptor, behaviorsByName);188  // Descriptors that should have their `desc` properties parsed as JSDoc.189  descriptor.properties.forEach(function(property) {190    // Feature properties are special, configuration is really just a matter of191    // inheritance...192    annotateProperty(property, descriptor.abstract);193  });194  // It may seem like overkill to always sort, but we have an assumption that195  // these properties are typically being consumed by user-visible tooling.196  // As such, it's good to have consistent output/ordering to aid the user.197  descriptor.properties.sort(function(a, b) {198    // Private properties are always last.199    if (a.private && !b.private) {200      return 1;201    } else if (!a.private && b.private) {202      return -1;203    // Otherwise, we're just sorting alphabetically.204    } else {205      return a.name.localeCompare(b.name);206    }207  });208  annotateElementHeader(descriptor);209  return descriptor;210}211/**212 * Annotates behavior descriptor.213 * @param {Object} descriptor behavior descriptor214 * @return {Object} descriptor passed in as param215 */216export function annotateBehavior(217    descriptor:BehaviorDescriptor): BehaviorDescriptor {218  annotate(descriptor);219  annotateElementHeader(descriptor);220  return descriptor;221}222/**223 * Annotates event documentation224 */225function _annotateEvent(descriptor:EventDescriptor): EventDescriptor {226  annotate(descriptor);227  // process @event228  var eventTag = jsdoc.getTag(descriptor.jsdoc, 'event');229  descriptor.name = eventTag ? eventTag.description : "N/A";230  // process @params231  descriptor.params = (descriptor.jsdoc.tags || [])232    .filter(function(tag) {233      return tag.tag === 'param';234    })235    .map(function(tag) {236      return {237        type: tag.type || "N/A",238        desc: tag.description,239        name: tag.name || "N/A"240      };241    });242  // process @params243  return descriptor;244}245/**246 * Annotates documentation found about a Hydrolysis property descriptor.247 *248 * @param {Object} descriptor The property descriptor.249 * @param {boolean} ignoreConfiguration If true, `configuration` is not set.250 * @return {Object} The descriptior that was given.251 */252function annotateProperty(253    descriptor:PropertyDescriptor,254    ignoreConfiguration:boolean): PropertyDescriptor {255  annotate(descriptor);256  if (descriptor.name[0] === '_' || jsdoc.hasTag(descriptor.jsdoc, 'private')) {257    descriptor.private = true;258  }259  if (!ignoreConfiguration &&260      ELEMENT_CONFIGURATION.indexOf(descriptor.name) !== -1) {261    descriptor.private       = true;262    descriptor.configuration = true;263  }264  // @type JSDoc wins265  descriptor.type =266      jsdoc.getTag(descriptor.jsdoc, 'type', 'type') || descriptor.type;267  if (descriptor.type.match(/^function/i)) {268    _annotateFunctionProperty(<FunctionDescriptor>descriptor);269  }270  // @default JSDoc wins271  var defaultTag = jsdoc.getTag(descriptor.jsdoc, 'default');272  if (defaultTag !== null) {273    var newDefault = (defaultTag.name || '') + (defaultTag.description || '');274    if (newDefault !== '') {275      descriptor.default = newDefault;276    }277  }278  return descriptor;279}280function _annotateFunctionProperty(descriptor:FunctionDescriptor) {281  descriptor.function = true;282  var returnTag = jsdoc.getTag(descriptor.jsdoc, 'return');283  if (returnTag) {284    descriptor.return = {285      type: returnTag.type,286      desc: returnTag.description,287    };288  }289  var paramsByName = {};290  (descriptor.params || []).forEach(function(param) {291    paramsByName[param.name] = param;292  });293  (descriptor.jsdoc && descriptor.jsdoc.tags || []).forEach(function(tag) {294    if (tag.tag !== 'param') return;295    var param = paramsByName[tag.name];296    if (!param) {297      return;298    }299    param.type = tag.type || param.type;300    param.desc = tag.description;301  });302}303/**304 * Converts raw features into an abstract `Polymer.Base` element.305 *306 * Note that docs on this element _are not processed_. You must call307 * `annotateElement` on it yourself if you wish that.308 *309 * @param {Array<FeatureDescriptor>} features310 * @return {ElementDescriptor}311 */312export function featureElement(313    features:FeatureDescriptor[]): ElementDescriptor {314  var properties = features.reduce<PropertyDescriptor[]>((result, feature) => {315    return result.concat(feature.properties);316  }, []);317  return {318    type:       'element',319    is:         'Polymer.Base',320    abstract:   true,321    properties: properties,322    desc: '`Polymer.Base` acts as a base prototype for all Polymer ' +323          'elements. It is composed via various calls to ' +324          '`Polymer.Base._addFeature()`.\n' +325          '\n' +326          'The properties reflected here are the combined view of all ' +327          'features found in this library. There may be more properties ' +328          'added via other libraries, as well.',329  };330}331/**332 * Cleans redundant properties from a descriptor, assuming that you have already333 * called `annotate`.334 *335 * @param {Object} descriptor336 */337export function clean(descriptor:Descriptor) {338  if (!descriptor.jsdoc) return;339  // The doctext was written to `descriptor.desc`340  delete descriptor.jsdoc.description;341  delete descriptor.jsdoc.orig;342  var cleanTags:jsdoc.Tag[] = [];343  (descriptor.jsdoc.tags || []).forEach(function(tag) {344    // Drop any tags we've consumed.345    if (HANDLED_TAGS.indexOf(tag.tag) !== -1) return;346    cleanTags.push(tag);347  });348  if (cleanTags.length === 0) {349    // No tags? no docs left!350    delete descriptor.jsdoc;351  } else {352    descriptor.jsdoc.tags = cleanTags;353  }354}355/**356 * Cleans redundant properties from an element, assuming that you have already357 * called `annotateElement`.358 *359 * @param {ElementDescriptor|BehaviorDescriptor} element360 */361export function cleanElement(element:ElementDescriptor) {362  clean(element);363  element.properties.forEach(cleanProperty);364}365/**366 * Cleans redundant properties from a property, assuming that you have already367 * called `annotateProperty`.368 *369 * @param {PropertyDescriptor} property370 */371function cleanProperty(property:PropertyDescriptor) {372  clean(property);373}374/**375 * Parse elements defined only in comments.376 * @param  {comments} Array<string> A list of comments to parse.377 * @return {ElementDescriptor}      A list of pseudo-elements.378 */379export function parsePseudoElements(comments: string[]):ElementDescriptor[] {380  var elements: ElementDescriptor[] = [];381  comments.forEach(function(comment) {382    var parsedJsdoc = jsdoc.parseJsdoc(comment);383    var pseudoTag = jsdoc.getTag(parsedJsdoc, 'pseudoElement', 'name');384    if (pseudoTag) {385      let element: ElementDescriptor = {386        is: pseudoTag,387        type: 'element',388        jsdoc: {description: parsedJsdoc.description, tags: parsedJsdoc.tags},389        properties: [],390        desc: parsedJsdoc.description,391      }392      annotateElementHeader(element);393      elements.push(element);394    }395  });396  return elements;397}398/**399 * @param {string} elementId400 * @param {DocumentAST} domModule401 * @param {DocumentAST} scriptElement The script that the element was402 *     defined in.403 */404function _findElementDocs(405    elementId:string, domModule:dom5.Node, scriptElement:dom5.Node) {406  // Note that we concatenate docs from all sources if we find them.407  // element can be defined in:408  // html comment right before dom-module409  // html commnet right before script defining the module,410  // if dom-module is empty411  var found:string[] = [];412  // Do we have a HTML comment on the `<dom-module>` or `<script>`?413  //414  // Confusingly, with our current style, the comment will be attached to415  // `<head>`, rather than being a sibling to the `<dom-module>`416  var searchRoot = domModule || scriptElement;417  var parents = dom5.nodeWalkAllPrior(searchRoot, dom5.isCommentNode);418  var comment = parents.length > 0 ? parents[0] : null;419  if (comment && comment.data) {420    found.push(comment.data);421  }422  if (found.length === 0) return null;423  return found424    .filter(function(comment) {425      // skip @license comments426      if (comment && comment.indexOf('@license') === -1) {427        return true;428      }429      else {430        return false;431      }432    })433    .map(jsdoc.unindent).join('\n');434}435function _findLastChildNamed(name:string, parent:dom5.Node) {436  var children = parent.childNodes;437  for (var i = children.length - 1; i >= 0; i--) {438    let child = children[i];439    if (child.nodeName === name) return child;440  }441  return null;442}443// TODO(nevir): parse5-utils!444function _getNodeAttribute(node:dom5.Node, name:string) {445  for (var i = 0; i < node.attrs.length; i++) {446    let attr = node.attrs[i];447    if (attr.name === name) {448      return attr.value;449    }450  }...Es5Binding.ts
Source:Es5Binding.ts  
1import * as binding from '../interfaces';2import Binding from '../Binding';3import has from '../../has';4import { getPropertyDescriptor, isEqual, isObject } from '../../util';5/**6 * The Es5Binding class enables two-way binding directly to properties of plain JavaScript objects in EcmaScript 5+7 * environments.8 */9class Es5Binding<T> extends Binding<T> {10	static test(kwArgs: binding.IBindingArguments): boolean {11		if (!has('es5') || !isObject(kwArgs.object) || typeof kwArgs.path !== 'string' ||12			(has('webidl-bad-descriptors') && typeof Node !== 'undefined' && kwArgs.object instanceof Node)13		) {14			return false;15		}16		var descriptor = Object.getOwnPropertyDescriptor(kwArgs.object, kwArgs.path);17		return descriptor ? descriptor.configurable && ('value' in descriptor || 'set' in descriptor) :18			Object.isExtensible(kwArgs.object);19	}20	/**21	 * The bound object.22	 */23	// Uses `any` type since this code uses arbitrary properties24	private _object: any;25	/**26	 * The original property descriptor for the bound object.27	 */28	private _originalDescriptor: PropertyDescriptor;29	/**30	 * The property descriptor generated for this binding.31	 */32	private _ownDescriptor: PropertyDescriptor;33	/**34	 * The name of the property to bind on the source object.35	 */36	private _property: string;37	constructor(kwArgs: binding.IBindingArguments) {38		super(kwArgs);39		var self = this;40		var object: any = kwArgs.object;41		var property = kwArgs.path;42		this._object = object;43		this._property = property;44		// TODO: Improve efficiency by adding a notification overlay to the object so these functions only ever get45		// attached once and additional binding observers can just reuse the same generated data46		var value = object[property];47		var descriptor = this._originalDescriptor = getPropertyDescriptor(object, property);48		var newDescriptor: PropertyDescriptor = {49			enumerable: descriptor ? descriptor.enumerable : true,50			configurable: descriptor ? descriptor.configurable : true51		};52		if (descriptor && (descriptor.get || descriptor.set)) {53			newDescriptor.get = descriptor.get;54			newDescriptor.set = function (newValue: T) {55				// If the binding was destroyed but the descriptor could not be fully removed because someone else56				// replaced it after us, we do not want to perform notifications, just continue to perform the original57				// operation58				if (self.notify) {59					var oldValue: T = descriptor.get ? descriptor.get.call(this) : value;60					if (descriptor.set) {61						descriptor.set.apply(this, arguments);62					}63					else {64						value = newValue;65					}66					if (descriptor.get) {67						newValue = descriptor.get.call(this);68					}69					if (!isEqual(oldValue, newValue)) {70						self.notify({ oldValue: oldValue, value: newValue });71					}72				}73				else if (descriptor.set) {74					descriptor.set.apply(this, arguments);75				}76			};77		}78		else {79			newDescriptor.get = function (): T {80				return value;81			};82			newDescriptor.set = function (newValue: T) {83				var oldValue: T = value;84				value = newValue;85				// If the binding was destroyed but the descriptor could not be fully removed because someone else86				// replaced it after us, we do not want to perform notifications, just continue to perform the original87				// operation88				if (self.notify && !isEqual(oldValue, value)) {89					self.notify({ oldValue: oldValue, value: value });90				}91			};92		}93		Object.defineProperty(object, property, newDescriptor);94		this._ownDescriptor = newDescriptor;95	}96	destroy() {97		super.destroy();98		// We can only replace the property's descriptor with the old one as long as we are in control of the99		// descriptor; if another binding was made to the same property after us, then the descriptor functions will not100		// be ours and we would incorrectly destroy the other bindings. If we are not in control, once `this.notify` is101		// null, our descriptor ends up functioning as a simple pass-through102		var currentDescriptor: PropertyDescriptor = Object.getOwnPropertyDescriptor(this._object, this._property);103		if (currentDescriptor.get === this._ownDescriptor.get && currentDescriptor.set === this._ownDescriptor.set) {104			var descriptor = this._originalDescriptor || {105				value: this._object[this._property],106				writable: true,107				enumerable: true,108				configurable: true109			};110			Object.defineProperty(this._object, this._property, descriptor);111		}112		this._ownDescriptor = this._originalDescriptor = this._object = this._property = this.notify = null;113	}114	get(): T {115		return this._object ? this._object[this._property] : undefined;116	}117	getObject(): {} {118		return this._object;119	}120	set(value: T): void {121		if (this._object) {122			this._object[this._property] = value;123		}124	}125}...Using AI Code Generation
1import { check, property } from "fast-check";2const isEven = (n: number) => n % 2 === 0;3const isOdd = (n: number) => !isEven(n);4const isEvenArb = fc.integer().filter(isEven);5const isOddArb = fc.integer().filter(isOdd);6describe("isEvenArb", () => {7  it("should only generate even numbers", () => {8    check(property(isEvenArb, isEven), { numRuns: 1000 });9  });10});11describe("isOddArb", () => {12  it("should only generate odd numbers", () => {13    check(property(isOddArb, isOdd), { numRuns: 1000 });14  });15});16import { check, property } from "fast-check";17const isEven = (n: number) => n % 2 === 0;18const isOdd = (n: number) => !isEven(n);19const isEvenArb = fc.integer().filter(isEven);20const isOddArb = fc.integer().filter(isOdd);21describe("isEvenArb", () => {22  it("should only generate even numbers", () => {23    check(property(isEvenArb, isEven), { numRuns: 1000 });24  });25});26describe("isOddArb", () => {27  it("should only generate odd numbers", () => {28    check(property(isOddArb, isOdd), { numRuns: 1000 });29  });30});31import { check, property } from "fast-check";32const isEven = (n: number) => n % 2 === 0;33const isOdd = (n: number) => !isEven(n);34const isEvenArb = fc.integer().filter(isEven);35const isOddArb = fc.integer().filter(isOdd);36describe("isEvenArb", () => {37  it("should only generate even numbers", () => {38    check(property(isEvenArb, isEven), { numRuns: 1000 });39  });40});41describe("isOddArb", () => {42  it("should only generate odd numbers", () => {43    check(property(isOddArUsing AI Code Generation
1const { describe, it } = require('mocha');2const fc = require('fast-check');3describe('test3', () => {4  it('test3', () => {5    fc.assert(6      fc.property(fc.integer(), fc.integer(), (a, b) => {7        return a + b === b + a;8      }),9    );10  });11});12const { describe, it } = require('mocha');13const fc = require('fast-check');14describe('test4', () => {15  it('test4', () => {16    fc.assert(17      fc.property(fc.integer(), fc.integer(), (a, b) => {18        return a + b === b + a;19      }),20    );21  });22});23const { describe, it } = require('mocha');24const fc = require('fast-check');25describe('test5', () => {26  it('test5', () => {27    fc.assert(28      fc.property(fc.integer(), fc.integer(), (a, b) => {29        return a + b === b + a;30      }),31    );32  });33});34const { describe, it } = require('mocha');35const fc = require('fast-check');36describe('test6', () => {37  it('test6', () => {38    fc.assert(39      fc.property(fc.integer(), fc.integer(), (a, b) => {40        return a + b === b + a;41      }),42    );43  });44});45const { describe, it } = require('mocha');46const fc = require('fast-check');47describe('test7', () => {48  it('test7', () => {49    fc.assert(50      fc.property(fc.integer(), fc.integer(), (a, b) => {51        return a + b === b + a;52      }),53    );54  });55});56const { describe, it } = require('mocha');57const fc = require('fast-check');58describe('test8', () => {Using AI Code Generation
1const fc = require('fast-check');2const { describe } = require('fast-check');3const { it } = require('fast-check');4describe('My first property-based test', () => {5    it('should always pass', () => {6        fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a));7    });8});9const fc = require('fast-check');10const { describe } = require('fast-check');11const { it } = require('fast-check');12describe('My first property-based test', () => {13    it('should always pass', () => {14        fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a));15    });16});17const fc = require('fast-check');18const { describe } = require('fast-check');19const { it } = require('fast-check');20describe('My first property-based test', () => {21    it('should always pass', () => {22        fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a));23    });24});25const fc = require('fast-check');26const { describe } = require('fast-check');27const { it } = require('fast-check');28describe('My first property-based test', () => {29    it('should always pass', () => {30        fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a));31    });32});33const fc = require('fast-check');34const { describe } = require('fast-check');35const { it } = require('fast-check');36describe('My first property-based test', () => {37    it('should always pass', () => {38        fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a));39    });40});41const fc = require('fast-check');42const { describe } = require('fast-check');43const { it } =Using AI Code Generation
1const { descriptor } = require('fast-check');2const { property } = require('fast-check');3const { arbitrary } = require('fast-check');4const { string } = require('fast-check');5const { array } = require('fast-check');6const { tuple } = require('fast-check');7const { command } = require('fast-check');8const { modelRun } = require('fast-check');9const { assert } = require('fast-check');10const { withCommands } = require('fast-check');11const { withSettings } = require('fast-check');12const { withMaxDepth } = require('fast-check');13const { withMaxSkips } = require('fast-check');14const { withMaxRuns } = require('fast-check');15const { withVerbose } = require('fast-check');16const { withInterruptAfter } = require('fast-check');17const { withRandom } = require('fast-check');18const { withDefaultSeed } = require('fast-check');19const { withSeed } = require('fast-check');20const { withPath } = require('fast-check');21const { withNextArbitrary } = require('fast-check');22const { withNextValue } = require('fast-check');23const { withShrinkableFor } = require('fast-check');24const { withShrunkOnce } = require('fast-check');25const { withLazy } = require('fast-check');26const { withReporters } = require('fast-check');27const { withLogger } = require('fast-check');28const { withPreConstraints } = require('fast-check');29const { withPostConstraints } = require('fast-check');30const { withGlobalConstraints } = require('fast-check');31const { withInterrupt } = require('fast-check');32const { withAsyncModelRun } = require('fast-check');33const { withAsyncBeforeCheckHook } = require('fast-check');34const { withAsyncAfterCheckHook } = require('fast-check');35const { withAsyncBeforeReplayHook } = require('fast-check');36const { withAsyncAfterReplayHook } = require('fast-check');37const { withAsyncBeforeNextHook } = require('fast-check');38const { withAsyncAfterNextHook } = require('fast-check');39const { withAsyncBeforeEndHook } = require('fast-check');40const { withAsyncAfterEndHook } = require('fast-check');41const { withAsyncBeforePathHook } = require('fast-check');42const { withAsyncAfterUsing AI Code Generation
1const { descriptor } = require('fast-check')2const test3 = descriptor({3  body: (t) => {4    t.pass()5  },6})7const { describe } = require('fast-check')8const test1 = require('./test1')9const test2 = require('./test2')10const test3 = require('./test3')11describe('test suite', () => {12  test1()13  test2()14  test3()15})16{17  "scripts": {18  },19  "dependencies": {20  }21}Using AI Code Generation
1const { check, property, gen } = require('fast-check');2const { descriptor } = gen;3const { string, number, constant } = gen;4const { oneof, tuple, record, array, dictionary, set, option, boolean } = gen;5const { mapToConstant, mapToConstantFromObject } = gen;6const { subarray, subrecord } = gen;7const { frequency } = gen;8const { option: option2, map, filter }Using AI Code Generation
1const fc = require('fast-check');2const { descriptor } = require('fast-check');3const isString = (s) => typeof s === 'string';4const isNumber = (s) => typeof s === 'number';5const isStringOrNumber = (s) => isString(s) || isNumber(s);6const isStringOrNumberDescriptor = descriptor(isStringOrNumber);7describe('isStringOrNumber', () => {8  it('should not throw on valid values', () => {9    fc.assert(10      fc.property(isStringOrNumberDescriptor, (value) => {11        expect(() => isStringOrNumber(value)).not.toThrow();12      })13    );14  });15  it('should throw on invalid values', () => {16    fc.assert(17      fc.property(fc.anything().filter((v) => !isStringOrNumberDescriptor.is(v)), (value) => {18        expect(() => isStringOrNumber(value)).toThrow();19      })20    );21  });22});23I think you need to import the descriptor function from fast-check-descriptor . I have a PR to fix this in the documentation here:Using AI Code Generation
1const fc = require('fast-check')2const myRandomNumber = fc.property(3  fc.integer(0, 100),4  fc.integer(0, 100),5  fc.integer(0, 100),6  (a, b, c) => a + b + c >= 07fc.assert(myRandomNumber)8const fc = require('fast-check')9const myRandomNumber = fc.property(10  fc.integer(0, 100),11  fc.integer(0, 100),12  fc.integer(0, 100),13  (a, b, c) => a + b + c >= 014fc.assert(myRandomNumber)15const fc = require('fast-check')16const myRandomNumber = fc.property(17  fc.integer(0, 100),18  fc.integer(0, 100),19  fc.integer(0, 100),20  (a, b, c) => a + b + c >= 021fc.assert(myRandomNumber)22const fc = require('fast-check')23const myRandomNumber = fc.property(24  fc.integer(0, 100),25  fc.integer(0, 100),26  fc.integer(0, 100),27  (a, b, c) => a + b + c >= 028fc.assert(myRandomNumber)29const fc = require('fast-check')30const myRandomNumber = fc.property(31  fc.integer(0, 100),32  fc.integer(0, 100),Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
