rescript-dom-testing-library
Version:
ReScript bindings for @testing-library/dom
72 lines (67 loc) • 3.43 kB
JavaScript
// Generated by ReScript, PLEASE EDIT WITH CARE
;
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 DomTestingLibrary = require("../src/DomTestingLibrary.js");
var Dom = require("@testing-library/dom");
var DomTestingLibrary__UserEvent = require("../src/DomTestingLibrary__UserEvent.js");
var render = (function(html) {
const body = document.querySelector('body', document)
body.innerHTML = html
return body
});
Jest.describe("UserEvent", (function (param) {
var setupMocks = (window.increment = () => {
window.count = window.count || 0;
return window.count++
});
beforeEach(function () {
return Curry._1(setupMocks, undefined);
});
afterEach(function () {
return (window.count = 0);
});
Jest.test("click", (function (param) {
DomTestingLibrary__UserEvent.click(undefined, undefined, DomTestingLibrary.getByRole(DomTestingLibrary.makeByRoleOptions(undefined, undefined, "Click me", undefined), {
NAME: "Str",
VAL: "button"
}, render("<button onclick=\"window.increment\">Click me</button>")));
return Jest.ExpectJs.toEqual(1, Jest.ExpectJs.expect(window.count));
}));
Jest.test("type", (function (param) {
var input = render("<input />");
DomTestingLibrary__UserEvent.type_(undefined, DomTestingLibrary.getByRole(undefined, {
NAME: "Str",
VAL: "textbox"
}, input), "four");
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByDisplayValue(undefined, {
NAME: "Str",
VAL: "four"
}, input)));
}));
Jest.testPromise("keyboard", undefined, (function (param) {
DomTestingLibrary__UserEvent.click(undefined, undefined, DomTestingLibrary.getByRole(undefined, {
NAME: "Str",
VAL: "textbox"
}, render("<input />")));
DomTestingLibrary__UserEvent.keyboard(undefined, "four");
return Dom.waitFor(function (param) {
return JestDom.toBeInTheDocument(expect(DomTestingLibrary.getByDisplayValue(undefined, {
NAME: "Str",
VAL: "four"
}, document)));
});
}));
return Jest.test("tab", (function (param) {
var html = render("<button>Save</button>");
var cancel = DomTestingLibrary.getByRole(DomTestingLibrary.makeByRoleOptions(undefined, undefined, "Save", undefined), {
NAME: "Str",
VAL: "button"
}, html);
var activeElement = document.activeElement;
return Jest.Expect.toBe(expect(cancel), activeElement);
}));
}));
exports.render = render;
/* Not a pure module */