How to use expectedFailurePath method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

Runner.spec.ts

Source:Runner.spec.ts Github

copy

Full Screen

1import * as fc from 'fast-check';2import { Value } from '../../../../src/check/arbitrary/definition/Value';3import { char } from '../../../../src/arbitrary/char';4import { IRawProperty } from '../../../../src/check/property/IRawProperty';5import { check, assert as rAssert } from '../../../../src/check/runner/Runner';6import { Random } from '../../../../src/random/generator/Random';7import { RunDetails } from '../../../../src/check/runner/reporter/RunDetails';8import { PreconditionFailure } from '../../../../src/check/precondition/PreconditionFailure';9import { Stream } from '../../../../src/stream/Stream';10import { VerbosityLevel } from '../../../../src/check/runner/configuration/VerbosityLevel';11const MAX_NUM_RUNS = 1000;12describe('Runner', () => {13 describe('check', () => {14 it('Should throw if property is null', () => {15 expect(() => check(null as any as IRawProperty<unknown>)).toThrowError();16 });17 it('Should throw if property is not a property at all', () => {18 expect(() => check({} as IRawProperty<unknown>)).toThrowError();19 });20 it('Should throw if property is an Arbitrary', () => {21 expect(() => check(char() as any as IRawProperty<unknown>)).toThrowError();22 });23 it.each`24 isAsync25 ${false}26 ${true}27 `('Should throw if both reporter and asyncReporter are defined (isAsync: $isAsync)', ({ isAsync }) => {28 const p: IRawProperty<[number]> = {29 isAsync: () => isAsync,30 generate: () => new Value([0], undefined),31 shrink: () => Stream.nil(),32 run: () => null,33 };34 expect(() => check(p, { reporter: () => {}, asyncReporter: async () => {} })).toThrowError();35 });36 it('Should not throw if reporter is specified on synchronous properties', () => {37 const p: IRawProperty<[number]> = {38 isAsync: () => false,39 generate: () => new Value([0], undefined),40 shrink: () => Stream.nil(),41 run: () => null,42 };43 expect(() => check(p, { reporter: () => {} })).not.toThrowError();44 });45 it('Should not throw if reporter is specified on asynchronous properties', () => {46 const p: IRawProperty<[number]> = {47 isAsync: () => true,48 generate: () => new Value([0], undefined),49 shrink: () => Stream.nil(),50 run: () => null,51 };52 expect(() => check(p, { reporter: () => {} })).not.toThrowError();53 });54 it('Should throw if asyncReporter is specified on synchronous properties', () => {55 const p: IRawProperty<[number]> = {56 isAsync: () => false,57 generate: () => new Value([0], undefined),58 shrink: () => Stream.nil(),59 run: () => null,60 };61 expect(() => check(p, { asyncReporter: async () => {} })).toThrowError();62 });63 it('Should not throw if asyncReporter is specified on asynchronous properties', () => {64 const p: IRawProperty<[number]> = {65 isAsync: () => true,66 generate: () => new Value([0], undefined),67 shrink: () => Stream.nil(),68 run: () => null,69 };70 expect(() => check(p, { asyncReporter: async () => {} })).not.toThrowError();71 });72 it('Should call the property 100 times by default (on success)', () => {73 let numCallsGenerate = 0;74 let numCallsRun = 0;75 const p: IRawProperty<[number]> = {76 isAsync: () => false,77 generate: () => {78 expect(numCallsRun).toEqual(numCallsGenerate); // called run before calling back79 ++numCallsGenerate;80 return new Value([numCallsGenerate] as [number], undefined);81 },82 shrink: () => Stream.nil(),83 run: (value: [number]) => {84 expect(value[0]).toEqual(numCallsGenerate); // called with previously generated value85 ++numCallsRun;86 return null;87 },88 };89 const out = check(p) as RunDetails<[number]>;90 expect(numCallsGenerate).toEqual(100);91 expect(numCallsRun).toEqual(100);92 expect(out.failed).toBe(false);93 });94 it('Should call the property 100 times even when path provided (on success)', () => {95 let numCallsGenerate = 0;96 let numCallsRun = 0;97 const p: IRawProperty<[number]> = {98 isAsync: () => false,99 generate: () => {100 expect(numCallsRun).toEqual(numCallsGenerate); // called run before calling back101 ++numCallsGenerate;102 return new Value([numCallsGenerate] as [number], undefined);103 },104 shrink: () => Stream.nil(),105 run: (value: [number]) => {106 expect(value[0]).toEqual(numCallsGenerate); // called with previously generated value107 ++numCallsRun;108 return null;109 },110 };111 const out = check(p, { path: '3002' }) as RunDetails<[number]>;112 expect(numCallsGenerate).toEqual(100);113 expect(numCallsRun).toEqual(100);114 expect(out.failed).toBe(false);115 });116 it('Should call the property on all shrunk values for path (on success)', () => {117 let numCallsGenerate = 0;118 let numCallsRun = 0;119 const p: IRawProperty<[number]> = {120 isAsync: () => false,121 generate: () => {122 ++numCallsGenerate;123 return new Value<[number]>([0], 'shrink-me');124 },125 shrink: (value) => {126 function* g() {127 if (value.context !== 'shrink-me') {128 return;129 }130 for (let i = 0; i !== 1234; ++i) {131 yield new Value<[number]>([0], undefined);132 }133 }134 return new Stream(g());135 },136 run: () => {137 ++numCallsRun;138 return null;139 },140 };141 const out = check(p, { path: '3002:0' }) as RunDetails<[number]>;142 expect(numCallsGenerate).toEqual(1);143 expect(numCallsRun).toEqual(1234);144 expect(out.failed).toBe(false);145 });146 it('Should ignore precondition failure runs and generate another value', async () => {147 const gapsBetweenSuccessesArb = fc.array(fc.nat(10), { minLength: 100, maxLength: 100 });148 const successfulRunIdsArb = gapsBetweenSuccessesArb.map((gaps) =>149 gaps.reduce((prev: number[], cur: number) => {150 prev.push(prev.length === 0 ? cur : prev[prev.length - 1] + cur + 1);151 return prev;152 }, [])153 );154 await fc.assert(155 fc.asyncProperty(156 successfulRunIdsArb,157 fc.boolean(),158 fc.option(fc.nat(99)),159 async (successIds, isAsyncProp, failAtId) => {160 let numCallsGenerate = 0;161 let numCallsRun = 0;162 const p: IRawProperty<[number]> = {163 isAsync: () => isAsyncProp,164 generate: () => new Value([numCallsGenerate++] as [number], undefined),165 shrink: () => Stream.nil(),166 run: (value: [number]) => {167 ++numCallsRun;168 const successId = successIds.indexOf(value[0]);169 if (successId !== -1)170 return successId === failAtId ? { error: new Error(), errorMessage: 'failed' } : null;171 return new PreconditionFailure();172 },173 };174 const out = await check(p);175 if (failAtId == null) {176 const expectedGenerate = successIds[successIds.length - 1] + 1;177 const expectedSkips = expectedGenerate - 100;178 expect(numCallsGenerate).toEqual(expectedGenerate);179 expect(numCallsRun).toEqual(expectedGenerate);180 expect(out.numRuns).toEqual(100);181 expect(out.numSkips).toEqual(expectedSkips);182 expect(out.failed).toBe(false);183 } else {184 const expectedGenerate = successIds[failAtId] + 1;185 const expectedSkips = expectedGenerate - failAtId - 1;186 expect(numCallsGenerate).toEqual(expectedGenerate);187 expect(numCallsRun).toEqual(expectedGenerate);188 expect(out.numRuns).toEqual(failAtId + 1);189 expect(out.numSkips).toEqual(expectedSkips);190 expect(out.failed).toBe(true);191 }192 }193 )194 );195 });196 it('Should fail on too many precondition failures', async () => {197 await fc.assert(198 fc.asyncProperty(199 fc.nat(1000).chain((v) => fc.record({ maxSkipsPerRun: fc.constant(v), onlySuccessId: fc.nat(2 * v + 1) })),200 fc.boolean(),201 async (settings, isAsyncProp) => {202 let numCallsGenerate = 0;203 let numPreconditionFailures = 0;204 const p: IRawProperty<[number]> = {205 isAsync: () => isAsyncProp,206 generate: () => new Value([numCallsGenerate++] as [number], undefined),207 shrink: () => Stream.nil(),208 run: (value: [number]) => {209 if (value[0] === settings.onlySuccessId) return null;210 ++numPreconditionFailures;211 return new PreconditionFailure();212 },213 };214 const out = await check(p, { numRuns: 2, maxSkipsPerRun: settings.maxSkipsPerRun });215 const expectedSkips = 2 * settings.maxSkipsPerRun + 1;216 const expectedRuns = settings.onlySuccessId === expectedSkips ? 0 : 1;217 expect(out.numRuns).toEqual(expectedRuns);218 expect(numPreconditionFailures).toEqual(expectedSkips);219 expect(out.numSkips).toEqual(expectedSkips);220 expect(out.failed).toBe(true);221 }222 )223 );224 });225 it('Should never call shrink on success', () => {226 let numCallsGenerate = 0;227 let numCallsRun = 0;228 const p: IRawProperty<[number]> = {229 isAsync: () => false,230 generate: () => {231 ++numCallsGenerate;232 return new Value([0], undefined);233 },234 shrink: () => {235 throw 'Not implemented';236 },237 run: (_value: [number]) => {238 ++numCallsRun;239 return null;240 },241 };242 const out = check(p) as RunDetails<[number]>;243 expect(numCallsGenerate).toEqual(100);244 expect(numCallsRun).toEqual(100);245 expect(out.failed).toBe(false);246 });247 it('Should call the property 100 times by default (except on error)', () =>248 fc.assert(249 fc.property(fc.integer({ min: 1, max: 100 }), fc.integer(), (num, seed) => {250 let numCallsGenerate = 0;251 let numCallsRun = 0;252 const p: IRawProperty<[number]> = {253 isAsync: () => false,254 generate: () => {255 ++numCallsGenerate;256 return new Value([0], undefined);257 },258 shrink: () => Stream.nil(),259 run: (_value: [number]) => {260 return ++numCallsRun < num ? null : { error: new Error(), errorMessage: 'error' };261 },262 };263 const out = check(p, { seed: seed }) as RunDetails<[number]>;264 expect(numCallsGenerate).toEqual(num); // stopped generate at first failing run265 expect(numCallsRun).toEqual(num); // no shrink for first failing run266 expect(out.failed).toBe(true);267 expect(out.numRuns).toEqual(num);268 expect(out.seed).toEqual(seed);269 return true;270 })271 ));272 it('Should alter the number of runs when asked to', () =>273 fc.assert(274 fc.property(fc.nat(MAX_NUM_RUNS), (num) => {275 let numCallsGenerate = 0;276 let numCallsRun = 0;277 const p: IRawProperty<[number]> = {278 isAsync: () => false,279 generate: () => {280 ++numCallsGenerate;281 return new Value([0], undefined);282 },283 shrink: () => Stream.nil(),284 run: (_value: [number]) => {285 ++numCallsRun;286 return null;287 },288 };289 const out = check(p, { numRuns: num }) as RunDetails<[number]>;290 expect(numCallsGenerate).toEqual(num);291 expect(numCallsRun).toEqual(num);292 expect(out.failed).toBe(false);293 return true;294 })295 ));296 it('Should generate the same values given the same seeds', () =>297 fc.assert(298 fc.property(fc.integer(), (seed) => {299 const buildPropertyFor = function (runOn: number[]) {300 const p: IRawProperty<[number]> = {301 isAsync: () => false,302 generate: (rng: Random) => {303 return new Value([rng.nextInt()], undefined);304 },305 shrink: () => Stream.nil(),306 run: (value: [number]) => {307 runOn.push(value[0]);308 return null;309 },310 };311 return p;312 };313 const data1: number[] = [];314 const data2: number[] = [];315 check(buildPropertyFor(data1), { seed: seed });316 check(buildPropertyFor(data2), { seed: seed });317 expect(data2).toEqual(data1);318 return true;319 })320 ));321 it('Should never call shrink if endOnFailure', () => {322 const p: IRawProperty<[number]> = {323 isAsync: () => false,324 generate: () => {325 return new Value([0], undefined);326 },327 shrink: () => {328 throw 'Not implemented';329 },330 run: (_value: [number]) => {331 return { error: new Error(), errorMessage: 'failure' };332 },333 };334 const out = check(p, { endOnFailure: true }) as RunDetails<[number]>;335 expect(out.failed).toBe(true);336 expect(out.numShrinks).toEqual(0);337 });338 it('Should compute values for path before removing shrink if endOnFailure', () => {339 const p: IRawProperty<[number]> = {340 isAsync: () => false,341 generate: () => {342 return new Value([0], undefined);343 },344 shrink: (value) => {345 if (value.value[0] !== 0) {346 throw 'Not implemented';347 }348 return Stream.of(new Value([42], undefined));349 },350 run: (value: [number]) => {351 return value[0] === 42 ? { error: new Error(), errorMessage: 'failure' } : null;352 },353 };354 const out = check(p, { path: '0:0', endOnFailure: true }) as RunDetails<[number]>;355 expect(out.failed).toBe(true);356 expect(out.numShrinks).toEqual(0);357 });358 it('Should not provide list of failures by default (no verbose)', () => {359 const p: IRawProperty<[number]> = {360 isAsync: () => false,361 generate: () => new Value([42], undefined),362 shrink: () => Stream.nil(),363 run: () => ({ error: new Error(), errorMessage: 'failure' }),364 };365 const out = check(p) as RunDetails<[number]>;366 expect(out.failures).toHaveLength(0);367 });368 it('Should provide the list of failures in verbose mode', () => {369 const p: IRawProperty<[number]> = {370 isAsync: () => false,371 generate: () => new Value([42], undefined),372 shrink: (value) => {373 return value.value[0] === 42374 ? Stream.of(new Value([48], undefined), new Value([12], undefined))375 : Stream.nil();376 },377 run: () => ({ error: new Error(), errorMessage: 'failure' }),378 };379 const out = check(p, { verbose: true }) as RunDetails<[number]>;380 expect(out.failures).not.toHaveLength(0);381 expect(out.failures).toEqual([[42], [48]]);382 });383 it('Should build the right counterexamplePath', () =>384 fc.assert(385 fc.property(fc.integer(), fc.array(fc.nat(99), { minLength: 1, maxLength: 100 }), (seed, failurePoints) => {386 // Each entry (at index idx) in failurePoints represents the number of runs387 // required before failing for the level <idx>388 // Basically it must fail before the end of the execution (100 runs by default)389 // so failure points are between 0 and 99 inclusive390 let idx = 0;391 let remainingBeforeFailure = failurePoints[idx];392 const p: IRawProperty<[number]> = {393 isAsync: () => false,394 generate: (_mrng: Random) => new Value([0], failurePoints.length - 1),395 shrink: (value) => {396 const depth = value.context as number;397 if (depth <= 0) {398 return Stream.nil();399 }400 function* g(): IterableIterator<Value<[number]>> {401 while (true) yield new Value([0], depth - 1);402 }403 return new Stream(g());404 },405 run: (_value: [number]) => {406 if (--remainingBeforeFailure >= 0) return null;407 remainingBeforeFailure = failurePoints[++idx];408 return { error: new Error(), errorMessage: 'failure' };409 },410 };411 const expectedFailurePath = failurePoints.join(':');412 const out = check(p, { seed: seed }) as RunDetails<[number]>;413 expect(out.failed).toBe(true);414 expect(out.seed).toEqual(seed);415 expect(out.numRuns).toEqual(failurePoints[0] + 1);416 expect(out.numShrinks).toEqual(failurePoints.length - 1);417 expect(out.counterexamplePath).toEqual(expectedFailurePath);418 })419 ));420 it('Should wait on async properties to complete', async () =>421 fc.assert(422 fc.asyncProperty(fc.integer({ min: 1, max: 100 }), fc.integer(), async (num, seed) => {423 const delay = () => new Promise((resolve) => setTimeout(resolve, 0));424 let runnerHasCompleted = false;425 const waitingResolve: (() => void)[] = [];426 let numCallsGenerate = 0;427 let numCallsRun = 0;428 const p: IRawProperty<[number]> = {429 isAsync: () => true,430 generate: () => {431 ++numCallsGenerate;432 return new Value([1], undefined);433 },434 shrink: (value) => {435 return value.value[0] === 1 ? Stream.of(new Value([42], undefined)) : Stream.nil();436 },437 run: async (_value: [number]) => {438 await new Promise<void>((resolve) => {439 waitingResolve.push(resolve);440 });441 return ++numCallsRun < num ? null : { error: new Error(), errorMessage: 'error' };442 },443 };444 const checker = check(p, { seed: seed }) as Promise<RunDetails<[number]>>;445 checker.then(() => (runnerHasCompleted = true));446 await delay();447 while (waitingResolve.length > 0) {448 expect(waitingResolve).toHaveLength(1); // no multiple properties in parallel449 expect(runnerHasCompleted).toBe(false); // not completed yet450 waitingResolve.shift()!();451 await delay();452 }453 await delay();454 expect(runnerHasCompleted).toBe(true);455 const out = await checker;456 expect(numCallsGenerate).toEqual(num); // stopped generate at first failing run457 expect(numCallsRun).toEqual(num + 1); // stopped run one shrink after first failing run458 expect(out.failed).toBe(true);459 expect(out.numRuns).toEqual(num);460 expect(out.seed).toEqual(seed);461 expect(out.counterexample).toEqual([42]);462 return true;463 })464 ));465 it('Should not timeout if no timeout defined', async () => {466 const p: IRawProperty<[number]> = {467 isAsync: () => true,468 generate: () => new Value([1], undefined),469 shrink: () => Stream.nil(),470 run: async (_value: [number]) => null,471 };472 const out = await (check(p) as Promise<RunDetails<[number]>>);473 expect(out.failed).toBe(false);474 });475 it('Should not timeout if timeout not reached', async () => {476 const wait = (timeMs: number) => new Promise<null>((resolve) => setTimeout(() => resolve(null), timeMs));477 const p: IRawProperty<[number]> = {478 isAsync: () => true,479 generate: () => new Value([1], undefined),480 shrink: () => Stream.nil(),481 run: async (_value: [number]) => await wait(0),482 };483 const out = await (check(p, { timeout: 100 }) as Promise<RunDetails<[number]>>);484 expect(out.failed).toBe(false);485 });486 it('Should timeout if it reached the timeout', async () => {487 const wait = (timeMs: number) => new Promise<null>((resolve) => setTimeout(() => resolve(null), timeMs));488 const p: IRawProperty<[number]> = {489 isAsync: () => true,490 generate: () => new Value([1], undefined),491 shrink: () => Stream.nil(),492 run: async (_value: [number]) => await wait(100),493 };494 const out = await (check(p, { timeout: 0 }) as Promise<RunDetails<[number]>>);495 expect(out.failed).toBe(true);496 });497 it('Should timeout if task never ends', async () => {498 const neverEnds = () => new Promise<null>(() => {});499 const p: IRawProperty<[number]> = {500 isAsync: () => true,501 generate: () => new Value([1], undefined),502 shrink: () => Stream.nil(),503 run: async (_value: [number]) => await neverEnds(),504 };505 const out = await (check(p, { timeout: 0 }) as Promise<RunDetails<[number]>>);506 expect(out.failed).toBe(true);507 });508 });509 describe('assert', () => {510 const v1 = { toString: () => 'toString(value#1)' };511 const v2 = { a: 'Hello', b: 21 };512 const failingProperty: IRawProperty<[any, any]> = {513 isAsync: () => false,514 generate: () => new Value([v1, v2], undefined),515 shrink: () => Stream.nil(),516 run: (_v: [any, any]) => ({ error: new Error(), errorMessage: 'error in failingProperty' }),517 };518 const failingComplexProperty: IRawProperty<[any, any, any]> = {519 isAsync: () => false,520 generate: () => new Value([[v1, v2], v2, v1], undefined),521 shrink: () => Stream.nil(),522 run: (_v: [any, any, any]) => ({ error: new Error(), errorMessage: 'error in failingComplexProperty' }),523 };524 const successProperty: IRawProperty<[any, any]> = {525 isAsync: () => false,526 generate: () => new Value([v1, v2], undefined),527 shrink: () => Stream.nil(),528 run: (_v: [any, any]) => null,529 };530 it('Should throw if property is null', () => {531 expect(() => rAssert(null as any as IRawProperty<unknown>)).toThrowError();532 });533 it('Should throw if property is not a property at all', () => {534 expect(() => rAssert({} as IRawProperty<unknown>)).toThrowError();535 });536 it('Should throw if property is an Arbitrary', () => {537 expect(() => rAssert(char() as any as IRawProperty<unknown>)).toThrowError();538 });539 it('Should never throw if no failure occured', () => {540 expect(() => rAssert(successProperty, { seed: 42 })).not.toThrow();541 });542 it('Should throw on failure', () => {543 expect(() => rAssert(failingProperty, { seed: 42 })).toThrowError();544 });545 it('Should put the seed in error message', () => {546 expect(() => rAssert(failingProperty, { seed: 42 })).toThrowError(`seed: 42, path:`);547 });548 it('Should put the number of tests in error message', () => {549 expect(() => rAssert(failingProperty, { seed: 42 })).toThrowError(`failed after 1 test`);550 });551 it('Should pretty print the failing example in error message', () => {552 expect(() => rAssert(failingProperty, { seed: 42 })).toThrowError(`[${v1.toString()},${JSON.stringify(v2)}]`);553 });554 it('Should pretty print the failing complex example in error message', () => {555 expect(() => rAssert(failingComplexProperty, { seed: 42 })).toThrowError(556 `[[${v1.toString()},${JSON.stringify(v2)}],${JSON.stringify(v2)},${v1.toString()}]`557 );558 });559 it('Should put the orginal error in error message', () => {560 expect(() => rAssert(failingProperty, { seed: 42 })).toThrowError(`Got error: error in failingProperty`);561 });562 describe('Impact of VerbosityLevel in case of failure', () => {563 const baseErrorMessage = '';564 const p: IRawProperty<[number]> = {565 isAsync: () => false,566 generate: () => {567 return new Value([42], undefined);568 },569 shrink: (value) => {570 return value.value[0] === 42571 ? Stream.of(new Value([48], undefined), new Value([12], undefined))572 : Stream.nil();573 },574 run: () => ({ error: new Error(), errorMessage: 'failure' }),575 };576 it('Should throw with base message by default (no verbose)', () => {577 expect(() => rAssert(p)).toThrowError(baseErrorMessage);578 });579 it('Should throw without list of failures by default (no verbose)', () => {580 expect(() => rAssert(p)).not.toThrowError('Encountered failures were:');581 });582 it('Should throw without execution tree by default (no verbose)', () => {583 expect(() => rAssert(p)).not.toThrowError('Execution summary:');584 });585 it('Should throw with base message in verbose mode', () => {586 expect(() => rAssert(p, { verbose: VerbosityLevel.Verbose })).toThrowError(baseErrorMessage);587 });588 it('Should throw with list of failures in verbose mode', () => {589 expect(() => rAssert(p, { verbose: VerbosityLevel.Verbose })).toThrowError('Encountered failures were:');590 });591 it('Should throw without execution tree in verbose mode', () => {592 expect(() => rAssert(p, { verbose: VerbosityLevel.Verbose })).not.toThrowError('Execution summary:');593 });594 it('Should throw with base message in very verbose mode', () => {595 expect(() => rAssert(p, { verbose: VerbosityLevel.VeryVerbose })).toThrowError(baseErrorMessage);596 });597 it('Should throw without list of failures in very verbose mode', () => {598 expect(() => rAssert(p, { verbose: VerbosityLevel.VeryVerbose })).not.toThrowError(599 'Encountered failures were:'600 );601 });602 it('Should throw with execution tree in very verbose mode', () => {603 expect(() => rAssert(p, { verbose: VerbosityLevel.VeryVerbose })).toThrowError('Execution summary:');604 });605 });606 describe('Impact of VerbosityLevel in case of too many skipped runs', () => {607 const baseErrorMessage = 'Failed to run property, too many pre-condition failures encountered';608 const p: IRawProperty<[number]> = {609 isAsync: () => false,610 generate: () => new Value([42], undefined),611 shrink: () => Stream.nil(),612 run: () => new PreconditionFailure(),613 };614 it('Should throw with base message by default (no verbose)', () => {615 expect(() => rAssert(p)).toThrowError(baseErrorMessage);616 });617 it('Should throw without list of failures by default (no verbose)', () => {618 expect(() => rAssert(p)).not.toThrowError('Encountered failures were:');619 });620 it('Should throw without execution tree by default (no verbose)', () => {621 expect(() => rAssert(p)).not.toThrowError('Execution summary:');622 });623 it('Should throw with base message in verbose mode', () => {624 expect(() => rAssert(p, { verbose: VerbosityLevel.Verbose })).toThrowError(baseErrorMessage);625 });626 it('Should throw without list of failures in verbose mode', () => {627 expect(() => rAssert(p, { verbose: VerbosityLevel.Verbose })).not.toThrowError('Encountered failures were:');628 });629 it('Should throw without execution tree in verbose mode', () => {630 expect(() => rAssert(p, { verbose: VerbosityLevel.Verbose })).not.toThrowError('Execution summary:');631 });632 it('Should throw with base message in very verbose mode', () => {633 expect(() => rAssert(p, { verbose: VerbosityLevel.VeryVerbose })).toThrowError(baseErrorMessage);634 });635 it('Should throw without list of failures in very verbose mode', () => {636 expect(() => rAssert(p, { verbose: VerbosityLevel.VeryVerbose })).not.toThrowError(637 'Encountered failures were:'638 );639 });640 it('Should throw with execution tree in very verbose mode', () => {641 expect(() => rAssert(p, { verbose: VerbosityLevel.VeryVerbose })).toThrowError('Execution summary:');642 });643 });644 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { AsyncProperty } = require('fast-check/lib/check/arbitrary/AsyncProperty.generic');3const { asyncProperty } = require('fast-check/lib/check/property/AsyncProperty');4const { asyncPropertyNoShrink } = require('fast-check/lib/check/property/AsyncPropertyNoShrink');5const { asyncPropertyNoShrinkNoPrint } = require('fast-check/lib/check/property/AsyncPropertyNoShrinkNoPrint');6const { expect } = require('chai');7const expectedFailurePath = (asyncProperty) => {8 .run()9 .then((out) => {10 if (out.failed === true) {11 return out.counterexample;12 } else {13 throw new Error('Not failed');14 }15 })16 .catch((e) => {17 throw e;18 });19};20describe('test', () => {21 it('should fail', (done) => {22 const asyncProperty = asyncPropertyNoShrink(fc.integer(), fc.integer(), (a, b) => {23 return new Promise((resolve, reject) => {24 setTimeout(() => {25 resolve(a + b);26 }, 1000);27 });28 });29 expectedFailurePath(asyncProperty)30 .then((counterexample) => {31 expect(counterexample).to.eql([1, 1]);32 done();33 })34 .catch((e) => {35 done(e);36 });37 });38});

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { expectedFailurePath } = require('fast-check-monorepo');3const arb = fc.integer(0, 100);4fc.assert(5 fc.property(arb, (a) => {6 return a > 100;7 }),8 { seed: 1, path: expectedFailurePath }9);10const fc = require('fast-check');11const { expectedFailurePath } = require('fast-check-monorepo');12const arb = fc.integer(0, 100);13fc.assert(14 fc.property(arb, (a) => {15 return a > 100;16 }),17 { seed: 1, path: expectedFailurePath }18);19Error: Property failed after 1 tests (seed: 1, path: 1)20 at Object.<anonymous> (/home/ashish/Projects/fast-check-monorepo/test.js:9:11)21 at Module._compile (internal/modules/cjs/loader.js:1137:30)22 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)23 at Module.load (internal/modules/cjs/loader.js:985:32)24 at Function.Module._load (internal/modules/cjs/loader.js:878:14)25 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)26Error: Property failed after 1 tests (seed: 1, path: 1)27 at Object.<anonymous> (/home/ashish/Projects/fast-check-monorepo/test2.js:9:11)28 at Module._compile (internal/modules/cjs/loader.js:1137:30)29 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)30 at Module.load (internal/modules/cjs/loader.js:985:32)31 at Function.Module._load (internal/modules/cjs/loader.js:878:14)32 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { expectedFailurePath } = require('fast-check');2const { assert } = require('chai');3describe('test', () => {4 it('test', () => {5 const result = expectedFailurePath(() => {6 assert.equal(1, 2);7 });8 console.log(result);9 });10});

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const expectedFailurePath = require('fast-check-monorepo').expectedFailurePath;3const fcArb = fc.integer();4const fcArb2 = fc.integer();5const fcArb3 = fc.integer();6const fcArb4 = fc.integer();7const fcArb5 = fc.integer();8const fcArb6 = fc.integer();9const fcArb7 = fc.integer();10const fcArb8 = fc.integer();11const fcArb9 = fc.integer();12const fcArb10 = fc.integer();13const fcArb11 = fc.integer();14const fcArb12 = fc.integer();15const fcArb13 = fc.integer();16const fcArb14 = fc.integer();17const fcArb15 = fc.integer();18const fcArb16 = fc.integer();19const fcArb17 = fc.integer();20const fcArb18 = fc.integer();21const fcArb19 = fc.integer();22const fcArb20 = fc.integer();23const fcArb21 = fc.integer();24const fcArb22 = fc.integer();25const fcArb23 = fc.integer();26const fcArb24 = fc.integer();27const fcArb25 = fc.integer();28const fcArb26 = fc.integer();29const fcArb27 = fc.integer();30const fcArb28 = fc.integer();31const fcArb29 = fc.integer();32const fcArb30 = fc.integer();33const fcArb31 = fc.integer();34const fcArb32 = fc.integer();35const fcArb33 = fc.integer();36const fcArb34 = fc.integer();37const fcArb35 = fc.integer();38const fcArb36 = fc.integer();39const fcArb37 = fc.integer();40const fcArb38 = fc.integer();41const fcArb39 = fc.integer();42const fcArb40 = fc.integer();43const fcArb41 = fc.integer();44const fcArb42 = fc.integer();45const fcArb43 = fc.integer();46const fcArb44 = fc.integer();47const fcArb45 = fc.integer();48const fcArb46 = fc.integer();49const fcArb47 = fc.integer();50const fcArb48 = fc.integer();51const fcArb49 = fc.integer();52const fcArb50 = fc.integer();53const fcArb51 = fc.integer();54const fcArb52 = fc.integer();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {expectedFailurePath} = require('fast-check-monorepo')2const fc = require('fast-check')3const prop = fc.property(4 fc.integer(),5 fc.integer(),6 fc.integer(),7 (a, b, c) => {8 }9fc.assert(10 fc.property(prop, (p) => {11 return expectedFailurePath(p)12 })13fc.assert(14 fc.property(prop, (p) => {15 return expectedFailurePath(p, 123)16 })17fc.assert(18 fc.property(prop, (p) => {19 return expectedFailurePath(p, 123, 200)20 })21fc.assert(22 fc.property(prop, (p) => {23 return expectedFailurePath(p, 123, 200, 2)24 })25fc.assert(26 fc.property(prop, (p) => {27 return expectedFailurePath(p, 123, 200, 2, 20)28 })

Full Screen

Using AI Code Generation

copy

Full Screen

1import {expectedFailurePath} from '../../src/fast-check-monorepo'2const test = require('tape')3test('expectedFailurePath', t => {4 t.plan(1)5 t.deepEqual(6 expectedFailurePath(),7})8{9 "scripts": {10 },11 "dependencies": {12 }13}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful