handle error runs with typed errors better
This commit is contained in:
parent
8e16d8fbfd
commit
a284288312
|
@ -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;
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue