class-static-initializers.js 806 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. test("basic functionality", () => {
  2. var called = false;
  3. class A {
  4. static {
  5. expect(called).toBeFalse();
  6. expect(this.name).toBe("A");
  7. called = true;
  8. }
  9. }
  10. expect(called).toBeTrue();
  11. new A();
  12. expect(called).toBeTrue();
  13. });
  14. test("called in order", () => {
  15. var i = 0;
  16. class A {
  17. static {
  18. expect(i).toBe(0);
  19. i++;
  20. }
  21. static method() {
  22. return 2;
  23. }
  24. static {
  25. expect(i).toBe(1);
  26. i++;
  27. }
  28. }
  29. expect(i).toBe(2);
  30. new A();
  31. expect(i).toBe(2);
  32. });
  33. test("correct this", () => {
  34. var thisValue = null;
  35. class A {
  36. static {
  37. thisValue = this;
  38. }
  39. }
  40. expect(thisValue).toBe(A);
  41. });