rescript-dom-testing-library
Version:
ReScript bindings for @testing-library/dom
396 lines (379 loc) • 24.1 kB
JavaScript
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';
var Jest = require("@glennsl/bs-jest/lib/js/src/jest.js");
var Curry = require("rescript/lib/js/curry.js");
var JestDom = require("bs-jest-dom/lib/js/src/JestDom.js");
var Caml_option = require("rescript/lib/js/caml_option.js");
var DomTestingLibrary = require("../src/DomTestingLibrary.js");
var Dom = require("@testing-library/dom");
var render = (function(html) {
const body = document.querySelector('body', document)
body.innerHTML = html
return body
});
var renderWithDelay = (function(html, delay) {
const body = document.querySelector('body');
setTimeout(() => {
body.innerHTML = html
}, delay)
return body
});
function then_(promise, fn) {
return promise.then(Curry.__1(fn));
}
var $$Promise = {
then_: then_
};
Jest.describe("byLabel", (function (param) {
Jest.test("getByLabel", (function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByLabelText(undefined, {
NAME: "Str",
VAL: "Title"
}, render("<label for=\"title\">Title</label><input type=\"text\" id=\"title\" />"))));
}));
Jest.test("getByLabel - exact as false", (function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByLabelText(DomTestingLibrary.makeByLabelTextOptions(undefined, false, undefined, undefined), {
NAME: "Str",
VAL: "title"
}, render("<label for=\"title\">Title</label><input type=\"text\" id=\"title\" />"))));
}));
return Jest.testPromise("findByLabel", undefined, (function (param) {
var promise = DomTestingLibrary.findByLabelText(undefined, {
NAME: "Str",
VAL: "Title"
}, render("<label for=\"title\">Title</label><input type=\"text\" id=\"title\" />"));
return promise.then(function (actual) {
return Promise.resolve(JestDom.toBeInTheDocument(expect(actual)));
});
}));
}));
Jest.describe("byText", (function (param) {
Jest.test("getByText", (function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByText(undefined, render("<span>Hello world</span>"), {
NAME: "Str",
VAL: "Hello world"
})));
}));
Jest.test("getByText - exact as false", (function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByText(DomTestingLibrary.makeByTextOptions(undefined, false, undefined, undefined, undefined), render("<span>Hello world</span>"), {
NAME: "Str",
VAL: "hello world"
})));
}));
Jest.testPromise("findByText", undefined, (function (param) {
var promise = DomTestingLibrary.findByText(undefined, {
NAME: "Str",
VAL: "Hello world"
}, render("<span>Hello world</span>"));
return promise.then(function (el) {
return Promise.resolve(JestDom.toBeInTheDocument(expect(el)));
});
}));
Jest.test("getAllByText", (function (param) {
return Jest.Expect.toHaveLength(3, Jest.Expect.expect(DomTestingLibrary.getAllByText(undefined, {
NAME: "RegExp",
VAL: new RegExp("Color")
}, render("<select>\n <option role=\"option\">Color Red</option>\n <option role=\"option\">Color Green</option>\n <option role=\"option\">Color Blue</option>\n </select>"))));
}));
Jest.test("queryAllByText", (function (param) {
return Jest.Expect.toHaveLength(3, Jest.Expect.expect(DomTestingLibrary.queryAllByText(undefined, {
NAME: "RegExp",
VAL: new RegExp("Color")
}, render("<select>\n <option role=\"option\">Color Red</option>\n <option role=\"option\">Color Green</option>\n <option role=\"option\">Color Blue</option>\n </select>"))));
}));
return Jest.testPromise("findAllByText", undefined, (function (param) {
var promise = DomTestingLibrary.findAllByText(undefined, {
NAME: "RegExp",
VAL: new RegExp("Color")
}, render("<select>\n <option role=\"option\">Color Red</option>\n <option role=\"option\">Color Green</option>\n <option role=\"option\">Color Blue</option>\n </select>"));
return promise.then(function (el) {
return Promise.resolve(Jest.Expect.toHaveLength(3, Jest.Expect.expect(el)));
});
}));
}));
Jest.describe("byRole", (function (param) {
Jest.test("getByRole - regex", (function (param) {
var options = DomTestingLibrary.makeByRoleOptionsWithRegex(undefined, undefined, Caml_option.some(new RegExp("color green", "i")), undefined);
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByRole(options, {
NAME: "Str",
VAL: "option"
}, render("<option role=\"option\">Color Green</option>"))));
}));
Jest.test("getByRole - function", (function (param) {
var options = DomTestingLibrary.makeByRoleOptionsWithFunction(undefined, undefined, (function (content, _element) {
return content === "Color Green";
}), undefined);
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByRole(options, {
NAME: "Str",
VAL: "option"
}, render("<option role=\"option\">Color Green</option>"))));
}));
Jest.testPromise("findByRole", undefined, (function (param) {
var options = DomTestingLibrary.makeByRoleOptions(undefined, undefined, "Red Color", undefined);
var promise = DomTestingLibrary.findByRole(options, {
NAME: "Str",
VAL: "option"
}, render("<option role=\"option\">Red Color</option>"));
return promise.then(function (el) {
return Promise.resolve(JestDom.toBeInTheDocument(expect(el)));
});
}));
Jest.testPromise("findAllByRole", undefined, (function (param) {
var promise = DomTestingLibrary.findAllByRole(undefined, {
NAME: "Str",
VAL: "option"
}, render("<select>\n <option role=\"option\">Color Red</option>\n <option role=\"option\">Color Green</option>\n <option role=\"option\">Color Blue</option>\n </select>"));
return promise.then(function (el) {
return Promise.resolve(Jest.Expect.toHaveLength(3, Jest.Expect.expect(el)));
});
}));
Jest.test("getAllByRole", (function (param) {
return Jest.Expect.toHaveLength(3, Jest.Expect.expect(DomTestingLibrary.getAllByRole(undefined, {
NAME: "Str",
VAL: "option"
}, render("<select>\n <option role=\"option\">Color Red</option>\n <option role=\"option\">Color Green</option>\n <option role=\"option\">Color Blue</option>\n </select>"))));
}));
return Jest.test("queryAllByRole", (function (param) {
return Jest.Expect.toHaveLength(3, Jest.Expect.expect(DomTestingLibrary.queryAllByRole(undefined, {
NAME: "Str",
VAL: "option"
}, render("<select>\n <option role=\"option\">Color Red</option>\n <option role=\"option\">Color Green</option>\n <option role=\"option\">Color Blue</option>\n </select>"))));
}));
}));
Jest.describe("byPlaceholderText", (function (param) {
Jest.test("getByPlaceholderText", (function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByPlaceholderText(undefined, {
NAME: "Str",
VAL: "title"
}, render("<input type=\"text\" placeholder=\"title\" />"))));
}));
Jest.test("getByPlaceholderText - exact as false", (function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByPlaceholderText(DomTestingLibrary.makeByPlaceholderTextOptions(false, undefined, undefined), {
NAME: "Str",
VAL: "title"
}, render("<input type=\"text\" placeholder=\"Title\" />"))));
}));
Jest.testPromise("findByPlaceholderText", undefined, (function (param) {
var promise = DomTestingLibrary.findByPlaceholderText(undefined, {
NAME: "Str",
VAL: "title"
}, render("<input type=\"text\" placeholder=\"title\" />"));
return promise.then(function (el) {
return Promise.resolve(JestDom.toBeInTheDocument(expect(el)));
});
}));
Jest.test("getAllByPlaceholderText", (function (param) {
return Jest.Expect.toHaveLength(1, Jest.Expect.expect(DomTestingLibrary.getAllByPlaceholderText(undefined, {
NAME: "Str",
VAL: "title"
}, render("<input type=\"text\" placeholder=\"title\" />"))));
}));
Jest.test("queryAllByPlaceholderText", (function (param) {
return Jest.Expect.toHaveLength(1, Jest.Expect.expect(DomTestingLibrary.queryAllByPlaceholderText(undefined, {
NAME: "Str",
VAL: "title"
}, render("<input type=\"text\" placeholder=\"title\" />"))));
}));
return Jest.testPromise("findByPlaceholderText", undefined, (function (param) {
var promise = DomTestingLibrary.findAllByPlaceholderText(undefined, {
NAME: "Str",
VAL: "title"
}, render("<input type=\"text\" placeholder=\"title\" />"));
return promise.then(function (el) {
return Promise.resolve(Jest.Expect.toHaveLength(1, Jest.Expect.expect(el)));
});
}));
}));
Jest.describe("byDisplayValue", (function (param) {
Jest.test("getByDisplayValue", (function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByDisplayValue(undefined, {
NAME: "Str",
VAL: "Red"
}, render("<input type=\"text\" placeholder=\"title\" value=\"Red\" />"))));
}));
Jest.test("getByDisplayValue - exact as false", (function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByDisplayValue(DomTestingLibrary.makeByDisplayValueOptions(false, undefined, undefined), {
NAME: "Str",
VAL: "red"
}, render("<input type=\"text\" placeholder=\"title\" value=\"Red\" />"))));
}));
Jest.testPromise("findByDisplayValue", undefined, (function (param) {
var promise = DomTestingLibrary.findByDisplayValue(undefined, {
NAME: "Str",
VAL: "Red"
}, render("<input type=\"text\" placeholder=\"title\" value=\"Red\" />"));
return promise.then(function (el) {
return Promise.resolve(JestDom.toBeInTheDocument(expect(el)));
});
}));
Jest.test("getAllByDisplayValue", (function (param) {
return Jest.Expect.toHaveLength(1, Jest.Expect.expect(DomTestingLibrary.getAllByDisplayValue(undefined, {
NAME: "Str",
VAL: "Red"
}, render("<input type=\"text\" placeholder=\"title\" value=\"Red\" />"))));
}));
Jest.test("queryAllByDisplayValue", (function (param) {
return Jest.Expect.toHaveLength(1, Jest.Expect.expect(DomTestingLibrary.queryAllByDisplayValue(undefined, {
NAME: "Str",
VAL: "Red"
}, render("<input type=\"text\" placeholder=\"title\" value=\"Red\" />"))));
}));
return Jest.testPromise("findAllByDisplayValue", undefined, (function (param) {
var promise = DomTestingLibrary.findAllByDisplayValue(undefined, {
NAME: "Str",
VAL: "Red"
}, render("<input type=\"text\" placeholder=\"title\" value=\"Red\" />"));
return promise.then(function (el) {
return Promise.resolve(Jest.Expect.toHaveLength(1, Jest.Expect.expect(el)));
});
}));
}));
Jest.describe("byAltText", (function (param) {
Jest.test("getByAltText", (function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByAltText(undefined, {
NAME: "Str",
VAL: "alt text example"
}, render("<img alt=\"alt text example\" />"))));
}));
Jest.testPromise("findByAltText", undefined, (function (param) {
var promise = DomTestingLibrary.findByAltText(undefined, {
NAME: "Str",
VAL: "alt text example"
}, render("<img alt=\"alt text example\" />"));
return promise.then(function (el) {
return Promise.resolve(JestDom.toBeInTheDocument(expect(el)));
});
}));
Jest.test("getByAltText - exact as false", (function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByAltText(DomTestingLibrary.makeByAltTextOptions(false, undefined, undefined), {
NAME: "Str",
VAL: "alt text example"
}, render("<img alt=\"alt text example\" />"))));
}));
Jest.test("getAllByAltText", (function (param) {
return Jest.Expect.toHaveLength(1, Jest.Expect.expect(DomTestingLibrary.getAllByAltText(undefined, {
NAME: "Str",
VAL: "alt text example"
}, render("<img alt=\"alt text example\" />"))));
}));
Jest.test("queryAllByAltText", (function (param) {
return Jest.Expect.toHaveLength(1, Jest.Expect.expect(DomTestingLibrary.queryAllByAltText(undefined, {
NAME: "Str",
VAL: "alt text example"
}, render("<img alt=\"alt text example\" />"))));
}));
return Jest.testPromise("findAllByAltText", undefined, (function (param) {
var promise = DomTestingLibrary.findAllByAltText(undefined, {
NAME: "Str",
VAL: "alt text example"
}, render("<img alt=\"alt text example\" />"));
return promise.then(function (el) {
return Promise.resolve(Jest.Expect.toHaveLength(1, Jest.Expect.expect(el)));
});
}));
}));
Jest.describe("byTitle", (function (param) {
Jest.test("getByTitle", (function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByTitle(undefined, {
NAME: "Str",
VAL: "title example"
}, render("<span title=\"title example\" />"))));
}));
Jest.test("getAllByTitle", (function (param) {
return Jest.Expect.toHaveLength(1, Jest.Expect.expect(DomTestingLibrary.getAllByTitle(undefined, {
NAME: "Str",
VAL: "title example"
}, render("<span title=\"title example\" />"))));
}));
Jest.test("queryAllByTitle", (function (param) {
return Jest.Expect.toHaveLength(1, Jest.Expect.expect(DomTestingLibrary.queryAllByTitle(undefined, {
NAME: "Str",
VAL: "title example"
}, render("<span title=\"title example\" />"))));
}));
Jest.testPromise("findAllByTitle", undefined, (function (param) {
var promise = DomTestingLibrary.findAllByTitle(undefined, {
NAME: "Str",
VAL: "title example"
}, render("<span title=\"title example\" />"));
return promise.then(function (el) {
return Promise.resolve(Jest.Expect.toHaveLength(1, Jest.Expect.expect(el)));
});
}));
Jest.test("getByTitle - exact as false", (function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByTitle(DomTestingLibrary.makeByTitleOptions(false, undefined, undefined), {
NAME: "Str",
VAL: "TITLE EXAMPLE"
}, render("<span title=\"title example\" />"))));
}));
return Jest.testPromise("findByTitle", undefined, (function (param) {
var promise = DomTestingLibrary.findByTitle(undefined, {
NAME: "Str",
VAL: "title example"
}, render("<span title=\"title example\" />"));
return promise.then(function (el) {
return Promise.resolve(JestDom.toBeInTheDocument(expect(el)));
});
}));
}));
Jest.describe("byTestId", (function (param) {
Jest.test("getByTestId", (function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByTestId(undefined, {
NAME: "Str",
VAL: "test-id"
}, render("<div data-testid=\"test-id\">Test ID</div>"))));
}));
Jest.test("getAllByTestId", (function (param) {
return Jest.Expect.toHaveLength(3, Jest.Expect.expect(DomTestingLibrary.getAllByTestId(undefined, {
NAME: "RegExp",
VAL: new RegExp("option")
}, render("<select>\n <option role=\"option\" data-testid=\"option\">Color Red</option>\n <option role=\"option\" data-testid=\"option\">Color Green</option>\n <option role=\"option\" data-testid=\"option\">Color Blue</option>\n </select>"))));
}));
Jest.test("queryAllByTestId", (function (param) {
return Jest.Expect.toHaveLength(3, Jest.Expect.expect(DomTestingLibrary.queryAllByTestId(undefined, {
NAME: "RegExp",
VAL: new RegExp("option")
}, render("<select>\n <option role=\"option\" data-testid=\"option\">Color Red</option>\n <option role=\"option\" data-testid=\"option\">Color Green</option>\n <option role=\"option\" data-testid=\"option\">Color Blue</option>\n </select>"))));
}));
Jest.test("getByTestId - exact as false", (function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByTestId(DomTestingLibrary.makeByTestIdOptions(false, undefined, undefined), {
NAME: "Str",
VAL: "test-id"
}, render("<div data-testid=\"TEST-ID\">Test ID</div>"))));
}));
Jest.testPromise("findAllByTestId", undefined, (function (param) {
var promise = DomTestingLibrary.findAllByTestId(undefined, {
NAME: "Str",
VAL: "opt"
}, render("<select>\n <option data-testid=\"opt\">Color Red</option>\n <option data-testid=\"opt\">Color Green</option>\n <option data-testid=\"opt\">Color Blue</option>\n </select>"));
return promise.then(function (el) {
return Promise.resolve(Jest.Expect.toHaveLength(3, Jest.Expect.expect(el)));
});
}));
return Jest.testPromise("findByTestId", undefined, (function (param) {
var promise = DomTestingLibrary.findByTestId(undefined, {
NAME: "Str",
VAL: "test-id"
}, render("<div data-testid=\"test-id\">Test ID</div>"));
return promise.then(function (el) {
return Promise.resolve(JestDom.toBeInTheDocument(expect(el)));
});
}));
}));
Jest.testPromise("waitFor", undefined, (function (param) {
return Dom.waitFor(function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByTestId(undefined, {
NAME: "Str",
VAL: "test-id"
}, renderWithDelay("<div data-testid=\"test-id\">Test ID</div>", 200))));
});
}));
Jest.test("prettyDOM", (function (param) {
var element = render("<select>\n <option role=\"option\">Color Red</option>\n <option role=\"option\">Color Green</option>\n <options role=\"option\">Color Blue</option>\n </select>");
DomTestingLibrary.debugScreen(undefined);
return Jest.Expect.toMatchSnapshot(Jest.Expect.expect(DomTestingLibrary.prettyDOM(undefined, undefined, element)));
}));
exports.render = render;
exports.renderWithDelay = renderWithDelay;
exports.$$Promise = $$Promise;
/* Not a pure module */