blob: 1deec41f767b37f99cc423b426c4e974e53ce144 (
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
|
test("in operator with objects", () => {
const o = { foo: "bar", bar: undefined };
expect("" in o).toBeFalse();
expect("foo" in o).toBeTrue();
expect("bar" in o).toBeTrue();
expect("baz" in o).toBeFalse();
expect("toString" in o).toBeTrue();
});
test("in operator with arrays", () => {
const a = ["hello", "friends"];
expect(0 in a).toBeTrue();
expect(1 in a).toBeTrue();
expect(2 in a).toBeFalse();
expect("0" in a).toBeTrue();
expect("hello" in a).toBeFalse();
expect("friends" in a).toBeFalse();
expect("length" in a).toBeTrue();
});
test("in operator with string object", () => {
const s = new String("foo");
expect("length" in s).toBeTrue();
});
test("error when used with primitives", () => {
["foo", 123, null, undefined].forEach(value => {
expect(() => {
"prop" in value;
}).toThrowWithMessage(TypeError, "'in' operator must be used on an object");
});
});
|