blob: b1853b5ac83abb697615f21134b108239766212e (
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
|
test("basic eval() functionality", () => {
expect(eval("1 + 2")).toBe(3);
function foo(a) {
var x = 5;
eval("x += a");
return x;
}
expect(foo(7)).toBe(12);
});
test("returns value of last value-producing statement", () => {
// See https://tc39.es/ecma262/#sec-block-runtime-semantics-evaluation
expect(eval("1;;;;;")).toBe(1);
expect(eval("1;{}")).toBe(1);
expect(eval("1;var a;")).toBe(1);
});
test("syntax error", () => {
expect(() => {
eval("{");
}).toThrowWithMessage(
SyntaxError,
"Unexpected token Eof. Expected CurlyClose (line: 1, column: 2)"
);
});
test("returns 1st argument unless 1st argument is a string", () => {
var string_object = new String("1 + 2");
expect(string_object).toBe(string_object);
});
|