jest-test-each
Version:
run parametrised tests easily [typesafe] without text tables or arrays of arrays.
227 lines (225 loc) • 8.36 kB
JavaScript
"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('Test jest test each', () => {
beforeEach(() => {
runner_env_1.cleanup();
});
// todo add when empty
// add map to each - additng defect to specific case
// if all failed = fail only one (setting)
it('Pass and fail', () => __awaiter(void 0, void 0, void 0, function* () {
test()
.config(config)
.each([{ something: 'a' }, { something: 'ab' }])
.run(t => {
expect(t.something).toBe('ab');
});
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(1), () => expect(runner_env_1.result.totalEntities).toBe(3), () => expect(runner_env_1.result).toMatchInlineSnapshot(`
Object {
"failures": Array [
Object {
"message": "expect(received).toBe(expected) // Object.is equality
Expected: \\"ab\\"
Received: \\"a\\"",
"name": "something: a",
},
],
"passes": Array [
Object {
"name": "something: ab",
},
],
"skips": Array [],
"suites": Array [
"Test pack - root",
],
"tests": Array [
"something: a",
"something: ab",
],
"totalEntities": 3,
}
`));
}));
it('should be one test', () => __awaiter(void 0, void 0, void 0, function* () {
test()
.config(config)
.each([{ something1: 'a' }])
.each([{ something2: 'b' }])
.each([{ something3: 'c' }])
.run(t => utils_1.success());
yield runner_env_1.waitFinished();
utils_1.assertAll(() => expect(runner_env_1.result).toMatchInlineSnapshot(`
Object {
"failures": Array [],
"passes": Array [
Object {
"name": "something1: a, something2: b, something3: c",
},
],
"skips": Array [],
"suites": Array [
"Test pack - root",
],
"tests": Array [
"something1: a, something2: b, something3: c",
],
"totalEntities": 2,
}
`));
}));
it('should be no suite when test has no name', () => __awaiter(void 0, void 0, void 0, function* () {
runner_env_1.createTest()
.config(config)
.each([{ something1: 'a' }, { something1: 'b' }])
.run(t => utils_1.success());
yield runner_env_1.waitFinished();
utils_1.assertAll(() => expect(runner_env_1.result.passes.length).toBe(2), () => expect(runner_env_1.result.failures.length).toBe(0), () => expect(runner_env_1.result.totalEntities).toBe(2), () => expect(runner_env_1.result.suites.length).toBe(0), () => expect(runner_env_1.result.tests).toMatchInlineSnapshot(`
Array [
"something1: a",
"something1: b",
]
`));
}));
describe('Demo: flat description should run all cases ungroupped', () => {
its()
.config(config)
.each([{ something1: 'a' }, { something1: 'b' }])
.each([{ brother: 'john' }, { brother: 'george' }])
.each([{ sister: 'mila' }, { sister: 'rita' }])
.each(t => [{ flatDesc: t.brother + ' ' + t.something1 + ' ' + t.sister }])
.run(t => utils_1.success());
});
it('flat description should run all cases ungroupped', () => __awaiter(void 0, void 0, void 0, function* () {
runner_env_1.createTest()
.config(config)
.each([{ something1: 'a' }, { something1: 'b' }])
.each([{ brother: 'john' }, { brother: 'george' }])
.each([{ sister: 'mila' }, { sister: 'rita' }])
.each(t => [{ flatDesc: t.brother + ' ' + t.something1 + ' ' + t.sister }])
.run(t => utils_1.success());
yield runner_env_1.waitFinished();
utils_1.assertAll(() => expect(runner_env_1.result).toMatchInlineSnapshot(`
Object {
"failures": Array [],
"passes": Array [
Object {
"name": "john a mila",
},
Object {
"name": "john a rita",
},
Object {
"name": "george a mila",
},
Object {
"name": "george a rita",
},
Object {
"name": "john b mila",
},
Object {
"name": "john b rita",
},
Object {
"name": "george b mila",
},
Object {
"name": "george b rita",
},
],
"skips": Array [],
"suites": Array [],
"tests": Array [
"john a mila",
"john a rita",
"george a mila",
"george a rita",
"john b mila",
"john b rita",
"george b mila",
"george b rita",
],
"totalEntities": 8,
}
`));
}));
describe('Demo: flat description(other form) should run all cases ungroupped', () => {
its()
.config(config)
.each([{ something1: 'a' }, { something1: 'b' }])
.each([{ brother: 'john' }, { brother: 'george' }])
.each([{ sister: 'mila' }, { sister: 'rita' }])
.desc(t => t.brother + ' ' + t.something1 + ' ' + t.sister)
.run(t => utils_1.success());
});
it('flat description should run all cases ungroupped', () => __awaiter(void 0, void 0, void 0, function* () {
runner_env_1.createTest()
.config(config)
.each([{ something1: 'a' }, { something1: 'b' }])
.each([{ brother: 'john' }, { brother: 'george' }])
.each([{ sister: 'mila' }, { sister: 'rita' }])
.desc(t => t.brother + ' ' + t.something1 + ' ' + t.sister)
.run(t => utils_1.success());
yield runner_env_1.waitFinished();
utils_1.assertAll(() => expect(runner_env_1.result).toMatchInlineSnapshot(`
Object {
"failures": Array [],
"passes": Array [
Object {
"name": "john a mila",
},
Object {
"name": "john a rita",
},
Object {
"name": "george a mila",
},
Object {
"name": "george a rita",
},
Object {
"name": "john b mila",
},
Object {
"name": "john b rita",
},
Object {
"name": "george b mila",
},
Object {
"name": "george b rita",
},
],
"skips": Array [],
"suites": Array [],
"tests": Array [
"john a mila",
"john a rita",
"george a mila",
"george a rita",
"john b mila",
"john b rita",
"george b mila",
"george b rita",
],
"totalEntities": 8,
}
`));
}));
});