| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("in operator with objects", () => { | 
					
						
							| 
									
										
										
										
											2021-04-17 01:46:48 +03:00
										 |  |  |     const sym = Symbol(); | 
					
						
							|  |  |  |     const o = { foo: "bar", bar: undefined, [sym]: "qux" }; | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect("" in o).toBeFalse(); | 
					
						
							|  |  |  |     expect("foo" in o).toBeTrue(); | 
					
						
							|  |  |  |     expect("bar" in o).toBeTrue(); | 
					
						
							|  |  |  |     expect("baz" in o).toBeFalse(); | 
					
						
							|  |  |  |     expect("toString" in o).toBeTrue(); | 
					
						
							| 
									
										
										
										
											2021-04-17 01:46:48 +03:00
										 |  |  |     expect(sym in o).toBeTrue(); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-04-23 16:06:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("in operator with arrays", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     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(); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-04-23 16:06:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("in operator with string object", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const s = new String("foo"); | 
					
						
							|  |  |  |     expect("length" in s).toBeTrue(); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-04-23 16:06:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("error when used with primitives", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     ["foo", 123, null, undefined].forEach(value => { | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             "prop" in value; | 
					
						
							|  |  |  |         }).toThrowWithMessage(TypeError, "'in' operator must be used on an object"); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); |