From a284288312d4396c2dba5bcecdc24ea1bf84ba87 Mon Sep 17 00:00:00 2001 From: ssube Date: Thu, 22 Jul 2021 13:39:13 -0500 Subject: [PATCH] handle error runs with typed errors better --- src/index.ts | 9 ++++++--- test/TestOver.ts | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index b1353fd..abfd032 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,14 +20,14 @@ export function over(name: string, strategy: Arbitrary, suite: Suite, p const examples: Array<[T]> = parameters.examples?.map((it) => [it]) || []; const checkParameters: Parameters<[T]> = { ...parameters, - // handle result formatting here + // clear these in favor of the errorReporter asyncReporter: undefined, reporter: undefined, examples, }; const reporter = (parameters.errorReporter || briefReporter) as ErrorReporter<[T]>; - // wrap the strategy arb in a one-shot property checking the test fn + // wrap the strategy arbitrary in a property checking the test fn // TODO: switch between property and asyncProperty as needed const property = asyncProperty(strategy, (val) => Promise.resolve(test.call(ctx, val))); return Promise.resolve(check(property, checkParameters)).then((result) => { @@ -87,5 +87,8 @@ export function isString(val: unknown): val is string { } export function isErrorRun(details: RunDetails): boolean { - return details.error?.startsWith('Error:') || false; + if (details.error) { + return /^([A-Z][a-z]*)*Error:/.test(details.error); + } + return false; } \ No newline at end of file diff --git a/test/TestOver.ts b/test/TestOver.ts index 6555d99..a87a2cb 100644 --- a/test/TestOver.ts +++ b/test/TestOver.ts @@ -16,7 +16,7 @@ describe('example properties', () => { }); it('should not throw', (n: number) => { - expect(n).to.equal(9); + throw new Error('bad number!'); }); it('should resolve async checks', async (n: number) => { @@ -35,7 +35,7 @@ describe('example properties', () => { }); it('should be long enough', (id: string) => { - return id.length > 2; + expect(id).to.have.length.greaterThan(2); }); }, { // fast-check parameters are supported, like examples