jest-test-each
Version:
run parametrised tests easily [typesafe] without text tables or arrays of arrays.
94 lines (91 loc) • 3.46 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");
describe('Async tests', () => {
const rootName = 'Test pack - root';
const test = () => runner_env_1.createTest(rootName);
const config = { groupBySuites: true, numericCases: false };
beforeEach(() => {
runner_env_1.cleanup();
});
it('Async test passes', () => __awaiter(void 0, void 0, void 0, function* () {
test()
.config(config)
.each([{ something: 'ab c' }, { something: 'ab d' }])
.run((t) => __awaiter(void 0, void 0, void 0, function* () {
yield utils_1.delay(10);
expect(t.something).toContain('ab');
}));
yield runner_env_1.waitFinished();
utils_1.assertAll(() => expect(runner_env_1.result).toMatchInlineSnapshot(`
Object {
"failures": Array [],
"passes": Array [
Object {
"name": "something: 'ab c'",
},
Object {
"name": "something: 'ab d'",
},
],
"skips": Array [],
"suites": Array [
"Test pack - root",
],
"tests": Array [
"something: 'ab c'",
"something: 'ab d'",
],
"totalEntities": 3,
}
`));
}));
it('Async test fails', () => __awaiter(void 0, void 0, void 0, function* () {
test()
.config(config)
.each([{ something: 'ab c' }, { something: 'ab d' }])
.run((t) => __awaiter(void 0, void 0, void 0, function* () {
yield utils_1.delay(10);
expect(t.something).not.toContain('ab');
}));
yield runner_env_1.waitFinished();
utils_1.assertAll(() => expect(runner_env_1.result).toMatchInlineSnapshot(`
Object {
"failures": Array [
Object {
"message": "expect(received).not.toContain(expected) // indexOf
Expected substring: not \\"ab\\"
Received string: \\"ab c\\"",
"name": "something: 'ab c'",
},
Object {
"message": "expect(received).not.toContain(expected) // indexOf
Expected substring: not \\"ab\\"
Received string: \\"ab d\\"",
"name": "something: 'ab d'",
},
],
"passes": Array [],
"skips": Array [],
"suites": Array [
"Test pack - root",
],
"tests": Array [
"something: 'ab c'",
"something: 'ab d'",
],
"totalEntities": 3,
}
`));
}));
});