test more complex properties
This commit is contained in:
parent
721cd8f3eb
commit
6bec31e4d1
11
src/index.ts
11
src/index.ts
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue