| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  | describe("correct behavior", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     test("length", () => { | 
					
						
							|  |  |  |         expect(Object.keys).toHaveLength(1); | 
					
						
							|  |  |  |         expect(Object.keys(true)).toHaveLength(0); | 
					
						
							|  |  |  |         expect(Object.keys(45)).toHaveLength(0); | 
					
						
							|  |  |  |         expect(Object.keys(-998)).toHaveLength(0); | 
					
						
							|  |  |  |         expect(Object.keys("abcd")).toHaveLength(4); | 
					
						
							|  |  |  |         expect(Object.keys([1, 2, 3])).toHaveLength(3); | 
					
						
							|  |  |  |         expect(Object.keys({ a: 1, b: 2, c: 3 })).toHaveLength(3); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-04-29 18:59:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     test("object argument", () => { | 
					
						
							|  |  |  |         let keys = Object.keys({ foo: 1, bar: 2, baz: 3 }); | 
					
						
							|  |  |  |         expect(keys).toEqual(["foo", "bar", "baz"]); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-04-29 18:59:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-07 21:39:36 -07:00
										 |  |  |     test("object argument with symbol keys", () => { | 
					
						
							|  |  |  |         let keys = Object.keys({ foo: 1, [Symbol("bar")]: 2, baz: 3 }); | 
					
						
							|  |  |  |         expect(keys).toEqual(["foo", "baz"]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     test("array argument", () => { | 
					
						
							|  |  |  |         let keys = Object.keys(["a", "b", "c"]); | 
					
						
							|  |  |  |         expect(keys).toEqual(["0", "1", "2"]); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-04-29 18:59:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     test("ignores non-enumerable properties", () => { | 
					
						
							|  |  |  |         let obj = { foo: 1 }; | 
					
						
							|  |  |  |         Object.defineProperty(obj, "getFoo", { | 
					
						
							|  |  |  |             value: function () { | 
					
						
							|  |  |  |                 return this.foo; | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |         keys = Object.keys(obj); | 
					
						
							|  |  |  |         expect(keys).toEqual(["foo"]); | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-04-29 18:59:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  | describe("errors", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     test("null argument value", () => { | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             Object.keys(null); | 
					
						
							|  |  |  |         }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-04-29 18:59:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     test("undefined argument value", () => { | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             Object.keys(undefined); | 
					
						
							|  |  |  |         }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  | }); |