1
0
Fork 0

handle error runs with typed errors better

This commit is contained in:
ssube 2021-07-22 13:39:13 -05:00
parent 8e16d8fbfd
commit a284288312
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
2 changed files with 8 additions and 5 deletions

View File

@ -20,14 +20,14 @@ export function over<T>(name: string, strategy: Arbitrary<T>, suite: Suite<T>, 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<T>(details: RunDetails<T>): boolean {
return details.error?.startsWith('Error:') || false;
if (details.error) {
return /^([A-Z][a-z]*)*Error:/.test(details.error);
}
return false;
}

View File

@ -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