summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/classes/class-static-getters.js
diff options
context:
space:
mode:
authorMatthew Olsson <matthewcolsson@gmail.com>2020-07-05 17:26:26 -0700
committerAndreas Kling <kling@serenityos.org>2020-07-06 23:40:35 +0200
commit15de2eda2b8c06a59053d6a7144ea9eaf07e2210 (patch)
tree191d9459dc71e270def1ca69a02406a9498005b9 /Libraries/LibJS/Tests/classes/class-static-getters.js
parent918f4affd51cdd285272770465d4d875f4ae5aa2 (diff)
downloadserenity-15de2eda2b8c06a59053d6a7144ea9eaf07e2210.zip
LibJS: Convert all remaining non-Array tests to the new system :)
Diffstat (limited to 'Libraries/LibJS/Tests/classes/class-static-getters.js')
-rw-r--r--Libraries/LibJS/Tests/classes/class-static-getters.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/Libraries/LibJS/Tests/classes/class-static-getters.js b/Libraries/LibJS/Tests/classes/class-static-getters.js
new file mode 100644
index 0000000000..0407bd9a48
--- /dev/null
+++ b/Libraries/LibJS/Tests/classes/class-static-getters.js
@@ -0,0 +1,80 @@
+describe("correct behavior", () => {
+ test("basic functionality", () => {
+ class A {
+ static get x() {
+ return 10;
+ }
+ }
+
+ expect(A.x).toBe(10);
+ expect(new A()).not.toHaveProperty("x");
+ });
+
+ test("name", () => {
+ class A {
+ static get x() {}
+ }
+
+ const d = Object.getOwnPropertyDescriptor(A, "x");
+ expect(d.get.name).toBe("get x");
+ });
+
+ test("extended name syntax", () => {
+ class A {
+ static get "method with space"() {
+ return 1;
+ }
+
+ static get 12() {
+ return 2;
+ }
+
+ static get [`he${"llo"}`]() {
+ return 3;
+ }
+ }
+
+ expect(A["method with space"]).toBe(1);
+ expect(A[12]).toBe(2);
+ expect(A.hello).toBe(3);
+ });
+
+ test("inherited static getter", () => {
+ class Parent {
+ static get x() {
+ return 3;
+ }
+ }
+
+ class Child extends Parent {}
+
+ expect(Parent.x).toBe(3);
+ expect(Child.x).toBe(3);
+ });
+
+ test("inherited static getter overriding", () => {
+ class Parent {
+ static get x() {
+ return 3;
+ }
+ }
+
+ class Child extends Parent {
+ static get x() {
+ return 10;
+ }
+ }
+
+ expect(Parent.x).toBe(3);
+ expect(Child.x).toBe(10);
+ });
+});
+
+describe("errors", () => {
+ test('"get static" is a syntax error', () => {
+ expect(`
+ class A {
+ get static foo() {}
+ }`).not.toEval();
+ });
+});