jest-test-each
Version:
run parametrised tests easily [typesafe] without text tables or arrays of arrays.
116 lines (115 loc) • 5.22 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 rootName = 'Test pack - root';
const test = () => runner_env_1.createTest(rootName);
const config = { groupBySuites: true, numericCases: false, concurrent: false };
describe('Test.only', () => {
beforeEach(() => {
runner_env_1.cleanup();
});
describe('should be 2 tests and one should fail when test.only', () => {
its()
.config(config)
.each([{ a: '1' }, { a: '2' }])
.each([{ b: '3' }, { b: '4' }])
//.only()
.run(t => utils_1.success());
it('wrapper', () => __awaiter(void 0, void 0, void 0, function* () {
test()
.config(config)
.each([{ a: '1' }, { a: '2' }])
.each([{ b: '3' }, { b: '4' }])
.only()
.run(t => utils_1.success());
yield runner_env_1.waitFinished();
utils_1.assertAll(() => expect(runner_env_1.result).toMatchInlineSnapshot(`
Object {
"failures": Array [
Object {
"message": "Do not forget to remove .only() from your test before committing",
"name": "only() should be removed before committing",
},
],
"passes": Array [
Object {
"name": "a: 1, b: 3",
},
],
"skips": Array [],
"suites": Array [
"Test pack - root",
],
"tests": Array [
"only() should be removed before committing",
"a: 1, b: 3",
],
"totalEntities": 3,
}
`));
}));
});
it('should fail when test.only and case is not found', () => __awaiter(void 0, void 0, void 0, function* () {
test()
.config(config)
.each([{ a: '1' }, { a: '2' }])
.each([{ b: '3' }, { b: '4' }])
.only(t => t.a === '3')
.run(t => utils_1.success());
yield runner_env_1.waitFinished();
utils_1.assertAll(() => expect(runner_env_1.result.passes.length).toBe(0), () => expect(runner_env_1.result.failures.length).toBe(1), () => expect(runner_env_1.result.totalEntities).toBe(1), () => expect(runner_env_1.result.suites.length).toBe(0), () => expect(runner_env_1.result.failures).toMatchInlineSnapshot(`
Array [
Object {
"message": "No such case: t => t.a === '3'",
"name": "Only one search failed",
},
]
`));
}));
it('should pass when test.only and case is found', () => __awaiter(void 0, void 0, void 0, function* () {
test()
.config(config)
.each([{ a: '1' }, { a: '2' }, { a: '3' }])
.each([{ b: '3' }, { b: '4' }])
.only(t => t.b === '4' && t.a === '3')
.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(1), () => expect(runner_env_1.result.totalEntities).toBe(3), () => expect(runner_env_1.result.passes).toMatchInlineSnapshot(`
Array [
Object {
"name": "a: 3, b: 4",
},
]
`));
}));
describe.skip('demo: should fail when no cases and test.only', () => {
its('Demo')
.config(config)
//.only()
.run(t => utils_1.success());
});
it('should fail when no cases and test.only', () => __awaiter(void 0, void 0, void 0, function* () {
test()
.config(config)
.only()
.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(1), () => expect(runner_env_1.result.suites.length).toBe(0), () => expect(runner_env_1.result.totalEntities).toBe(2), () => expect(runner_env_1.result.passes).toMatchInlineSnapshot(`
Array [
Object {
"name": "Test pack - root",
},
]
`), () => expect(runner_env_1.result.failures[0].name).toMatchInlineSnapshot(`"only() should be removed before committing"`));
}));
});