1
0
Fork 0

test more complex properties

This commit is contained in:
ssube 2021-07-21 00:13:20 -05:00
parent 721cd8f3eb
commit 6bec31e4d1
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
2 changed files with 22 additions and 3 deletions

View File

@ -13,12 +13,19 @@ export function over<T>(name: string, strategy: Arbitrary<T>, suite: Suite<T>):
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();

View File

@ -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;
});
});
});