UNPKG

playwright-testing-library

Version:
53 lines (52 loc) 2.55 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 }); exports.queryToSelector = exports.includes = exports.buildTestingLibraryScript = void 0; const fs_1 = require("fs"); const common_1 = require("../../common"); const helpers_1 = require("../helpers"); const queryToSelector = (query) => query.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); exports.queryToSelector = queryToSelector; const buildTestingLibraryScript = ({ config }) => __awaiter(void 0, void 0, void 0, function* () { const testingLibraryDom = yield fs_1.promises.readFile(require.resolve('@testing-library/dom/dist/@testing-library/dom.umd.js'), 'utf8'); const configuredTestingLibraryDom = (0, common_1.configureTestingLibraryScript)(testingLibraryDom, config); return ` ${configuredTestingLibraryDom} window.__testingLibraryReviver = ${helpers_1.reviver.toString()}; ${helpers_1.TestingLibraryDeserializedFunction.toString()}; `; }); exports.buildTestingLibraryScript = buildTestingLibraryScript; /** * Alternative version of `Array.prototype.includes` that allows testing for * the existence of an item with a type that is a _superset_ of the type of the * items in the array. * * This allows us to use it to check whether an item of type `string` exists in * an array of string literals (e.g: `['foo', 'bar'] as const`) without TypeScript * complaining. It will, however, throw a compiler error if you try to pass an item * of type `number`. * * @example * const things = ['foo', 'bar'] as const; * * // error * const hasThing = (t: string) => things.includes(t); * * // compiles * const hasThing = (t: string) => includes(things, t); * * @param array array to search * @param item item to search for */ const includes = (array, item) => array.includes(item); exports.includes = includes; //# sourceMappingURL=helpers.js.map