Serenity Operating System
at master 53 lines 1.1 kB view raw
1describe("correct behavior", () => { 2 test("basic functionality", () => { 3 let n = 0; 4 expect(++n).toBe(1); 5 expect(n).toBe(1); 6 7 n = 0; 8 expect(n++).toBe(0); 9 expect(n).toBe(1); 10 11 n = 0; 12 expect(--n).toBe(-1); 13 expect(n).toBe(-1); 14 15 n = 0; 16 expect(n--).toBe(0); 17 expect(n).toBe(-1); 18 19 let a = []; 20 expect(a++).toBe(0); 21 expect(a).toBe(1); 22 23 let b = true; 24 expect(b--).toBe(1); 25 expect(b).toBe(0); 26 }); 27 28 test("updates that produce NaN", () => { 29 let s = "foo"; 30 expect(++s).toBeNaN(); 31 expect(s).toBeNaN(); 32 33 s = "foo"; 34 expect(s++).toBeNaN(); 35 expect(s).toBeNaN(); 36 37 s = "foo"; 38 expect(--s).toBeNaN(); 39 expect(s).toBeNaN(); 40 41 s = "foo"; 42 expect(s--).toBeNaN(); 43 expect(s).toBeNaN(); 44 }); 45}); 46 47describe("errors", () => { 48 test("update expression throws reference error", () => { 49 expect(() => { 50 ++x; 51 }).toThrowWithMessage(ReferenceError, "'x' is not defined"); 52 }); 53});