@seanox/aspect-js
Version:
full stack JavaScript framework for SPAs incl. reactivity rendering, mvc / mvvm, models, expression language, datasource, routing, paths, unit test and some more
90 lines (79 loc) • 2.77 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();
// Object.defineProperty by default writable = true
Test.create({test() {
const o = {};
let serial = 0;
Object.defineProperty(o, "x", {
value: ++serial
});
Assert.assertEquals(1, o.x);
Assert.assertEquals(200, o.x = 200);
Assert.assertEquals(1, o.x);
}});
// Constants must function correctly in the scopes
Test.create({test() {
const a = 1; {
const a = 2; {
const a = 3;
Assert.assertEquals(3, a);}
Assert.assertEquals(2, a);}
Assert.assertEquals(1, a);
}});
// In maps, keys for set, get and has must be nullable.
Test.create({test() {
const map = new Map();
Assert.assertFalse(map.has(null));
map.set(null, 123);
Assert.assertTrue(map.has(null));
Assert.assertEquals(123, map.get(null));
Assert.assertUndefined(map.get());
}});
// The combination of Object.create(object) and Proxy must work as
// expected. Important here is the behavior of the Prototype of
// Object.create(object).
Test.create({test() {
const a = {x:1, w() {return this.x +1}};
const b = new Proxy(Object.create(a), {});
Assert.assertFalse(a == b);
a.w = function() {
return this.x + "_x";
};
a.z = function() {
return this.w() + "_o";
};
b.x = 2;
Assert.assertEquals("1_x_o", a.z());
Assert.assertEquals("2_x_o", b.z());
a.m = {o:5};
Assert.assertEquals("object", typeof a.m);
Assert.assertEquals("object", typeof b.m);
Assert.assertTrue(a.m == b.m);
b.m = new Proxy(b.m, {});
Assert.assertTrue(a.m != b.m);
a.u = 123
Assert.assertTrue(a.u === b.u);
b.u = 456;
Assert.assertTrue(a.u !== b.u);
delete a.u;
Assert.assertTrue(typeof a.u === "undefined");
Assert.assertTrue(typeof b.u === "number");
}});
Test.start({auto:true});
</script>
</head>
<body>
</body>
</html>