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