jest-test-each
Version:
run parametrised tests easily [typesafe] without text tables or arrays of arrays.
93 lines (92 loc) • 4.27 kB
JavaScript
;
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 index_1 = require("../../index");
const rootName = 'Test pack - root';
const test = () => runner_env_1.createTest(rootName);
describe('Configuration', () => {
beforeEach(() => {
runner_env_1.cleanup();
});
// check groupping
// check plain
const numeric = [
{ isNum: true, exp: '' },
{ isNum: false, exp: '' },
];
numeric.forEach(c => {
it(`cases should ${c.isNum ? '' : 'not '}be numbered when numericCases in setup is ${c.isNum}`, () => __awaiter(void 0, void 0, void 0, function* () {
index_1.TestEachSetup({ groupBySuites: true, numericCases: c.isNum });
test()
.each([{ something: 'a' }, { something: 'ab' }])
.run(t => {
expect(t.something).toBe('ab');
});
const num = (n) => (c.isNum ? `${n}. ` : '');
yield runner_env_1.waitFinished();
utils_1.assertAll(() => expect(runner_env_1.result.suites).toEqual([rootName]), () => expect(runner_env_1.result.tests).toEqual([`${num(1)}something: a`, `${num(2)}something: ab`]));
}));
});
numeric.forEach(c => {
it(`suites should ${c.isNum ? '' : 'not '}be numbered when numericCases in setup is ${c.isNum}`, () => __awaiter(void 0, void 0, void 0, function* () {
index_1.TestEachSetup({ groupBySuites: true, numericCases: c.isNum });
test()
.each([{ something: 'a' }, { something: 'ab' }])
.each([{ foo: 'a' }, { foo: 'ab' }])
.each([{ last: 'a' }, { last: 'b' }, { last: 'c' }])
.run(t => {
expect(1).toBe(1);
});
const num = (n) => (c.isNum ? `${n}. ` : '');
yield runner_env_1.waitFinished();
utils_1.assertAll(() => expect(runner_env_1.result.suites).toEqual([
'Test pack - root',
`${num(1)}something: a`,
`${num(1)}foo: a`,
`${num(2)}foo: ab`,
`${num(2)}something: ab`,
`${num(1)}foo: a`,
`${num(2)}foo: ab`,
]));
}));
});
describe('using configuration for each test', () => {
const testFunc = (num) => __awaiter(void 0, void 0, void 0, function* () {
test()
.config({ numericCases: num })
.each([{ something: 'a' }, { something: 'ab' }])
.run(t => {
expect(t.something).toBe('ab');
});
yield runner_env_1.waitFinished();
});
it('numeric', () => __awaiter(void 0, void 0, void 0, function* () {
yield testFunc(true);
utils_1.assertAll(() => expect(runner_env_1.result.suites).toEqual([rootName]), () => expect(runner_env_1.result.tests).toMatchInlineSnapshot(`
Array [
"1. something: a",
"2. something: ab",
]
`));
}));
it('not numeric', () => __awaiter(void 0, void 0, void 0, function* () {
yield testFunc(false);
utils_1.assertAll(() => expect(runner_env_1.result.suites).toEqual([rootName]), () => expect(runner_env_1.result.tests).toMatchInlineSnapshot(`
Array [
"something: a",
"something: ab",
]
`));
}));
});
});