1
0
Fork 0
mocha-foam/test/TestOver.ts

54 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-07-21 05:13:20 +00:00
import { integer, lorem, tuple, uuid } from 'fast-check';
2021-07-21 04:20:39 +00:00
import { over } from '../src/index';
describe('some foo', () => {
2021-07-21 04:39:29 +00:00
over('the bars', integer(), (it) => {
2021-07-21 04:54:15 +00:00
const large = Math.floor(Math.random() * 1_000_000);
2021-07-21 04:39:29 +00:00
it('should be a small number', (bar: number) => {
2021-07-21 04:54:15 +00:00
return bar < large;
});
it('should be even', (bar: number) => {
return bar % 2 === 0;
2021-07-21 04:20:39 +00:00
});
2021-07-21 23:28:22 +00:00
it('should not throw', (t: number) => {
if (t.toString()[3] === '9') {
throw new Error('not a real number!');
}
return true;
});
2021-07-21 04:20:39 +00:00
});
2021-07-21 04:50:21 +00:00
over('some IDs', uuid(), (it) => {
2021-07-21 23:28:22 +00:00
beforeEach(() => {
console.log('before each ID test');
});
2021-07-21 04:50:21 +00:00
it('should be a good one', (id: string) => {
return id[9] !== 'a';
});
2021-07-21 23:28:22 +00:00
it('should be long enough', (id: string) => {
return id.length > 2;
});
}, {
examples: [['a']],
numRuns: 1_000_000_000,
2021-07-21 04:50:21 +00:00
});
2021-07-21 05:13:20 +00:00
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;
});
});
2021-07-21 04:20:39 +00:00
});