From 6bec31e4d166e6c1347ca3c5c6e5d3cfab04d372 Mon Sep 17 00:00:00 2001 From: ssube Date: Wed, 21 Jul 2021 00:13:20 -0500 Subject: [PATCH] test more complex properties --- src/index.ts | 11 +++++++++-- test/TestOver.ts | 14 +++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 37167c7..7eb8243 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,12 +13,19 @@ export function over(name: string, strategy: Arbitrary, suite: Suite): return new Promise((res, rej) => { const result = check(property(strategy, (t) => test.call(ctx, t))); if (result.failed) { + console.log(result); if (result.counterexample !== null) { - const examples = result.counterexample.join(','); + const examples = result.counterexample.map(it => { + if (typeof it === 'string' && it.length === 0) { + return "''"; + } else { + return it; + } + }).join(','); const error = `failed after ${result.numRuns} runs and ${result.numShrinks} shrinks, failing on: ${examples}`; rej(new Error(error)); } else { - rej(new Error('failed without counterexample')); + rej(new Error(`failed after ${result.numRuns} runs and ${result.numShrinks} shrinks, without counterexamples`)); } } else { res(); diff --git a/test/TestOver.ts b/test/TestOver.ts index a60241f..7d1f752 100644 --- a/test/TestOver.ts +++ b/test/TestOver.ts @@ -1,4 +1,4 @@ -import { integer, uuid } from 'fast-check'; +import { integer, lorem, tuple, uuid } from 'fast-check'; import { over } from '../src/index'; @@ -19,4 +19,16 @@ describe('some foo', () => { return id[9] !== 'a'; }); }); + + over('even numbers', integer().filter(n => n % 2 === 0), (it) => { + it('should be even', (n: number) => { + return n % 2 === 0; + }); + }); + + over('mapped properties', tuple(lorem(), integer()).map(([a, b]) => a.substr(b)), (it) => { + it('should have content', (text: string) => { + return text.length > 0; + }); + }); });