@seanox/aspect-js
Version:
full stack JavaScript framework for SPAs incl. reactivity rendering, mvc / mvvm, models, expression language, datasource, virtual paths, unit test and some more
59 lines (54 loc) • 2.24 kB
HTML
<html>
<head>
<meta charset="ISO-8859-1">
<title>Seanox aspect-js test environment</title>
<style>
body {
font-family: monospace;
white-space: pre;
}
</style>
<script src="aspect-js.js"></script>
<script type="text/javascript">
Test.activate();
Namespace.create("eC", false);
Namespace.create("eT", false);
Namespace.create("eS", false);
Test.create({test() {
const text = snapshots.join("\r\n");
Assert.assertEquals(5, (text.match(/checked/g) || []).length);
Assert.assertEquals(4, (text.match(/disabled/g) || []).length);
Assert.assertEquals(3, (text.match(/xxx/g) || []).length);
}});
const snapshots = [];
Composite.listen(Composite.EVENT_RENDER_END, () => {
if (snapshots.length === 0) {
document.querySelector("input[type='checkbox']").checked = false;
document.querySelector("input[type='text']").disabled = false;
document.querySelector("span").removeAttribute("xxx");
}
let snapshot = document.body.innerHTML;
snapshot = snapshot.replace(/^\s+/mg, "");
snapshot = snapshot.replace(/<\!--([\s\.r\n].*?)*-->/g, "");
snapshots.push(snapshot.trim());
if (snapshots.length < 10) {
eC = [1,3,5,7,9].includes(snapshots.length);
eT = [0,2,4,6,8].includes(snapshots.length);
eS = [3,6,9].includes(snapshots.length);
Composite.render(document.body);
} else Test.start();
});
</script>
</head>
<body>
<!--
The attributes use expressions whose return value can be undefined.
In these cases, the attribute must be temporarily removed and restored at
the next render cycle if the return value is not undefined.
-->
<input type="checkbox" checked="{{eC ? false : undefined}}"/>
<input type="text" disabled="{{eT ? '' : undefined}}"/>
<span xxx="{{eS ? true : undefined}}"></span>
</body>
</html>