UNPKG

jest-test-each

Version:

run parametrised tests easily [typesafe] without text tables or arrays of arrays.

50 lines (49 loc) 2.77 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const runner_env_1 = require("../utils/runner-env"); const utils_1 = require("../utils/utils"); const rootName = 'Test pack - root'; const test = () => runner_env_1.createTest(rootName); const config = { groupBySuites: true, numericCases: false }; describe('Error handling', () => { beforeEach(() => { runner_env_1.cleanup(); }); it('should throw when no name and cases', () => __awaiter(void 0, void 0, void 0, function* () { const r = () => runner_env_1.createTest() .config(config) .run(t => utils_1.success()); utils_1.assertAll(() => expect(r).toThrow(new Error('From guard: Test should have name when no cases'))); })); it('should NOT throw when name and no cases', () => __awaiter(void 0, void 0, void 0, function* () { test() .config(config) .run(t => utils_1.success()); yield runner_env_1.waitFinished(); utils_1.assertAll(() => expect(runner_env_1.result.passes.length).toBe(1), () => expect(runner_env_1.result.failures.length).toBe(0), () => expect(runner_env_1.result.suites.length).toBe(0), () => expect(runner_env_1.result.totalEntities).toBe(1)); })); it('should throw when no data in some eaches', () => __awaiter(void 0, void 0, void 0, function* () { const notTotallyEmpty = () => test() .config(config) .each([{ a: 6 }, { a: 7 }]) .each([{}]) .run(t => utils_1.success()); utils_1.assertAll(() => expect(notTotallyEmpty).toThrow(new Error('From guard: Every case in .each should have not empty data'))); })); it('should throw when no data in some eaches - total empty', () => __awaiter(void 0, void 0, void 0, function* () { const empty = () => test() .config(config) .each([{}]) .run(t => utils_1.success()); utils_1.assertAll(() => expect(empty).toThrow(new Error('From guard: Every case in .each should have not empty data'))); })); });