woby
Version:
A high-performance framework with fine-grained observable/signal-based reactivity for building rich applications.
59 lines (58 loc) • 1.79 kB
JavaScript
import { s as setChild, F as FragmentUtils } from "./setters-Be-jpuHZ.js";
import { r as root } from "./root-Cy1I57g_.js";
const render = (child) => {
const fragment = document.createElement("div");
const renderDiv = document.createElement("div");
fragment.textContent = "";
let unmount = root((stack, dispose) => {
setChild(fragment, child, FragmentUtils.make(), stack);
renderDiv.append(fragment);
console.log("f", fragment.outerHTML);
console.log("c", fragment.children[0].outerHTML);
return () => {
dispose(stack);
fragment.textContent = "";
fragment.remove();
console.log("dispose");
};
});
document.body.append(renderDiv);
const getByRole = (tag) => fragment.querySelector(tag);
const getByTestId = (id) => {
if (fragment.querySelector(`[data-testid="${id}"]`)) {
return fragment.querySelector(`[data-testid="${id}"]`);
} else {
throw new Error("Element test ID not found ");
}
};
const getByText = (text) => {
function allDescendants(node) {
for (var i = 0; i < node.children.length; i++) {
var child2 = node.children[i];
if (typeof text === "string") {
if (child2.textContent == text) {
return child2;
}
} else {
if (text.test(child2.textContent)) {
return child2;
}
}
const returnValue2 = allDescendants(child2);
if (returnValue2) {
return returnValue2;
}
}
return null;
}
const returnValue = allDescendants(fragment);
if (!returnValue) {
throw new Error("Element not found");
}
};
return { fragment, unmount, getByRole, getByTestId, getByText };
};
export {
render
};
//# sourceMappingURL=testing.es.js.map