UNPKG

test-fns

Version:

write usecase driven tests systematically for simpler, safer, and more readable code

74 lines 3.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const givenWhenThen_1 = require("./givenWhenThen"); const doesPlantNeedWater = (plant) => plant.hydration === 'DRY'; describe('doesPlantNeedWater', () => { (0, givenWhenThen_1.given)('a plant', () => { (0, givenWhenThen_1.when)('the plant doesnt have enough water', () => { const plant = { id: 7, hydration: 'DRY', }; (0, givenWhenThen_1.then)('it should return true', () => { expect(doesPlantNeedWater(plant)).toEqual(true); }); givenWhenThen_1.then.skip('it should be possible to skip a test too', () => { throw new Error('should have been skipped'); }); givenWhenThen_1.then.todo('it should be possible to todo a test too', () => { throw new Error('should have been ignored'); }); }); (0, givenWhenThen_1.when)('the plant has enough water', () => { const plant = { id: 7, hydration: 'WET', }; (0, givenWhenThen_1.then)('it should return false', { because: 'because it has enough water' }, () => { expect(doesPlantNeedWater(plant)).toEqual(false); }); }); }); givenWhenThen_1.given.runIf(false)('runIf=false', () => { (0, givenWhenThen_1.then)('should be skipped', () => { throw new Error('should not have been run'); }); }); givenWhenThen_1.given.skipIf(false)('skipIf=false', () => { givenWhenThen_1.when.skipIf(true)('skipIf=true', () => { (0, givenWhenThen_1.then)('should be skipped', () => { throw new Error('should not have been run'); }); }); givenWhenThen_1.when.skipIf(false)('skipIf=false', () => { givenWhenThen_1.then.skipIf(true)('this should be skipped', () => { throw new Error('should not have been run'); }); givenWhenThen_1.then.skipIf(false)('this should run', () => { expect(true).toEqual(true); }); givenWhenThen_1.then.runIf(false)('this should be skipped', () => { throw new Error('should not have been run'); }); givenWhenThen_1.then.runIf(true)('this should run', () => { expect(true).toEqual(true); }); }); }); (0, givenWhenThen_1.given)('a probabilistic test', () => { (0, givenWhenThen_1.when)('criteria = EVERY', () => { givenWhenThen_1.then.repeatably({ attempts: 3, criteria: 'EVERY' })('it should succeed every time', () => { expect(true).toEqual(true); }); givenWhenThen_1.then.repeatably({ attempts: 3, criteria: 'EVERY' })('it should have access to the attempt counter', ({ attempt }) => { expect(attempt).toBeGreaterThan(0); }); }); (0, givenWhenThen_1.when)('criteria = SOME', () => { givenWhenThen_1.then.repeatably({ attempts: 5, criteria: 'SOME' })('it should have access to the attempt counter', async ({ attempt }) => { expect(attempt).toBeGreaterThan(3); }); }); }); }); //# sourceMappingURL=givenWhenThen.test.js.map