blob: 176beadb76922b0ec26e9736485a6264b65bd98f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
test("object with custom toString", () => {
const o = { toString: () => "foo" };
expect(o + "bar").toBe("foobar");
expect([o, "bar"].toString()).toBe("foo,bar");
});
test("object with uncallable toString and custom valueOf", () => {
const o = { toString: undefined, valueOf: () => "foo" };
expect(o + "bar").toBe("foobar");
expect([o, "bar"].toString()).toBe("foo,bar");
});
test("object with custom valueOf", () => {
const o = { valueOf: () => 42 };
expect(Number(o)).toBe(42);
expect(o + 1).toBe(43);
});
test("object with uncallable valueOf and custom toString", () => {
const o = { valueOf: undefined, toString: () => "42" };
expect(Number(o)).toBe(42);
expect(o + 1).toBe("421");
});
|