| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | test("toBe", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(null).toBe(null); | 
					
						
							|  |  |  |     expect(undefined).toBe(undefined); | 
					
						
							|  |  |  |     expect(null).not.toBe(undefined); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(1).toBe(1); | 
					
						
							|  |  |  |     expect(1).not.toBe(2); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect("1").toBe("1"); | 
					
						
							|  |  |  |     expect("1").not.toBe("2"); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(true).toBeTrue(); | 
					
						
							|  |  |  |     expect(true).not.toBeFalse(); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect({}).not.toBe({}); | 
					
						
							|  |  |  |     expect([]).not.toBe([]); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     function foo() {} | 
					
						
							|  |  |  |     expect(foo).toBe(foo); | 
					
						
							|  |  |  |     expect(function () {}).not.toBe(function () {}); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let s = Symbol("foo"); | 
					
						
							|  |  |  |     expect(s).toBe(s); | 
					
						
							|  |  |  |     expect(Symbol("foo")).not.toBe(Symbol("foo")); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(1n).toBe(1n); | 
					
						
							|  |  |  |     expect(1n).not.toBe(1); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  | test("toBeCloseTo", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(1).toBeCloseTo(1); | 
					
						
							|  |  |  |     expect(1).not.toBeCloseTo(1.1); | 
					
						
							|  |  |  |     expect(1).not.toBeCloseTo(1.01); | 
					
						
							|  |  |  |     expect(1).not.toBeCloseTo(1.001); | 
					
						
							|  |  |  |     expect(1).not.toBeCloseTo(1.0001); | 
					
						
							|  |  |  |     expect(1).not.toBeCloseTo(1.00001); | 
					
						
							|  |  |  |     expect(1).toBeCloseTo(1.000001); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         ["foo", 1], | 
					
						
							|  |  |  |         [1, "foo"], | 
					
						
							|  |  |  |         [1n, 1], | 
					
						
							|  |  |  |     ].forEach(arr => { | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             expect(arr[0]).toBeCloseTo(arr[1]); | 
					
						
							|  |  |  |         }).toThrow(ExpectationError); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | test("toHaveLength", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect([]).toHaveLength(0); | 
					
						
							|  |  |  |     expect([]).not.toHaveLength(1); | 
					
						
							|  |  |  |     expect([1]).toHaveLength(1); | 
					
						
							|  |  |  |     expect({ length: 1 }).toHaveLength(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(() => { | 
					
						
							|  |  |  |         expect(1).toHaveLength(); | 
					
						
							|  |  |  |     }).toThrow(ExpectationError); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toHaveProperty", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect([]).toHaveProperty("length"); | 
					
						
							|  |  |  |     expect([]).toHaveProperty("length", 0); | 
					
						
							|  |  |  |     expect([1]).not.toHaveProperty("length", 0); | 
					
						
							|  |  |  |     expect({ foo: "bar" }).toHaveProperty("foo"); | 
					
						
							|  |  |  |     expect({ foo: "bar" }).toHaveProperty("foo", "bar"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect({ foo: { bar: "baz" } }).toHaveProperty(["foo", "bar"]); | 
					
						
							|  |  |  |     expect({ foo: { bar: "baz" } }).toHaveProperty(["foo", "bar"], "baz"); | 
					
						
							|  |  |  |     expect({ foo: { bar: "baz" } }).toHaveProperty("foo.bar"); | 
					
						
							|  |  |  |     expect({ foo: { bar: "baz" } }).toHaveProperty("foo.bar", "baz"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect({ foo: { bar: "baz" } }).toHaveProperty(["foo", "bar"]); | 
					
						
							|  |  |  |     expect({ foo: { bar: "baz" } }).toHaveProperty(["foo", "bar"], "baz"); | 
					
						
							|  |  |  |     expect({ foo: { bar: "baz" } }).not.toHaveProperty(["foo", "baz"]); | 
					
						
							|  |  |  |     expect({ foo: { bar: "baz" } }).not.toHaveProperty(["foo", "baz"], "qux"); | 
					
						
							|  |  |  |     expect({ foo: { bar: "baz" } }).not.toHaveProperty("foo.baz"); | 
					
						
							|  |  |  |     expect({ foo: { bar: "baz" } }).not.toHaveProperty("foo.baz", "qux"); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toBeDefined", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(1).toBeDefined(); | 
					
						
							|  |  |  |     expect(true).toBeDefined(); | 
					
						
							|  |  |  |     expect(false).toBeDefined(); | 
					
						
							|  |  |  |     expect({}).toBeDefined(); | 
					
						
							|  |  |  |     expect([]).toBeDefined(); | 
					
						
							|  |  |  |     expect("a").toBeDefined(); | 
					
						
							|  |  |  |     expect(null).toBeDefined(); | 
					
						
							|  |  |  |     expect(undefined).not.toBeDefined(); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toBeInstanceOf", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(new Error()).toBeInstanceOf(Error); | 
					
						
							|  |  |  |     expect(Error).not.toBeInstanceOf(Error); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Parent {} | 
					
						
							|  |  |  |     class Child extends Parent {} | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(new Child()).toBeInstanceOf(Child); | 
					
						
							|  |  |  |     expect(new Child()).toBeInstanceOf(Parent); | 
					
						
							|  |  |  |     expect(new Parent()).toBeInstanceOf(Parent); | 
					
						
							|  |  |  |     expect(new Parent()).not.toBeInstanceOf(Child); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toBeNull", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(null).toBeNull(); | 
					
						
							|  |  |  |     expect(undefined).not.toBeNull(); | 
					
						
							|  |  |  |     expect(5).not.toBeNull(); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toBeUndefined", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(undefined).toBeUndefined(); | 
					
						
							|  |  |  |     expect(null).not.toBeUndefined(); | 
					
						
							|  |  |  |     expect().toBeUndefined(); | 
					
						
							|  |  |  |     expect(5).not.toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toBeNaN", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(NaN).toBeNaN(); | 
					
						
							|  |  |  |     expect(5).not.toBeNaN(); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | test("toBeTrue", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(true).toBeTrue(); | 
					
						
							|  |  |  |     expect(false).not.toBeTrue(); | 
					
						
							|  |  |  |     expect(null).not.toBeTrue(); | 
					
						
							|  |  |  |     expect(undefined).not.toBeTrue(); | 
					
						
							|  |  |  |     expect(0).not.toBeTrue(); | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toBeFalse", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(true).not.toBeFalse(); | 
					
						
							|  |  |  |     expect(false).toBeFalse(); | 
					
						
							|  |  |  |     expect(null).not.toBeFalse(); | 
					
						
							|  |  |  |     expect(undefined).not.toBeFalse(); | 
					
						
							|  |  |  |     expect(0).not.toBeFalse(); | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  | test("toBeLessThan", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(0).toBeLessThan(1); | 
					
						
							|  |  |  |     expect(0).toBeLessThan(0.1); | 
					
						
							|  |  |  |     expect(1).not.toBeLessThan(1); | 
					
						
							|  |  |  |     expect(1).not.toBeLessThan(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(0n).toBeLessThan(1n); | 
					
						
							|  |  |  |     expect(1n).not.toBeLessThan(1n); | 
					
						
							|  |  |  |     expect(1n).not.toBeLessThan(0n); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         ["foo", 0], | 
					
						
							|  |  |  |         [0, "foo"], | 
					
						
							|  |  |  |         [0, 0n], | 
					
						
							|  |  |  |         [0n, 0], | 
					
						
							|  |  |  |     ].forEach(arr => { | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             expect(arr[0]).toBeLessThan(arr[1]); | 
					
						
							|  |  |  |         }).toThrow(ExpectationError); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toBeLessThanOrEqual", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(0).toBeLessThanOrEqual(1); | 
					
						
							|  |  |  |     expect(0).toBeLessThanOrEqual(0.1); | 
					
						
							|  |  |  |     expect(1).toBeLessThanOrEqual(1); | 
					
						
							|  |  |  |     expect(1).not.toBeLessThanOrEqual(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(0n).toBeLessThanOrEqual(1n); | 
					
						
							|  |  |  |     expect(1n).toBeLessThanOrEqual(1n); | 
					
						
							|  |  |  |     expect(1n).not.toBeLessThanOrEqual(0n); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         ["foo", 0], | 
					
						
							|  |  |  |         [0, "foo"], | 
					
						
							|  |  |  |         [0, 0n], | 
					
						
							|  |  |  |         [0n, 0], | 
					
						
							|  |  |  |     ].forEach(arr => { | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             expect(arr[0]).toBeLessThanOrEqual(arr[1]); | 
					
						
							|  |  |  |         }).toThrow(ExpectationError); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toBeGreaterThan", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(1).toBeGreaterThan(0); | 
					
						
							|  |  |  |     expect(0.1).toBeGreaterThan(0); | 
					
						
							|  |  |  |     expect(1).not.toBeGreaterThan(1); | 
					
						
							|  |  |  |     expect(0).not.toBeGreaterThan(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(1n).toBeGreaterThan(0n); | 
					
						
							|  |  |  |     expect(1n).not.toBeGreaterThan(1n); | 
					
						
							|  |  |  |     expect(0n).not.toBeGreaterThan(1n); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         ["foo", 0], | 
					
						
							|  |  |  |         [0, "foo"], | 
					
						
							|  |  |  |         [0, 0n], | 
					
						
							|  |  |  |         [0n, 0], | 
					
						
							|  |  |  |     ].forEach(arr => { | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             expect(arr[0]).toBeGreaterThan(arr[1]); | 
					
						
							|  |  |  |         }).toThrow(ExpectationError); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toBeGreaterThanOrEqual", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(1).toBeGreaterThanOrEqual(0); | 
					
						
							|  |  |  |     expect(0.1).toBeGreaterThanOrEqual(0); | 
					
						
							|  |  |  |     expect(1).toBeGreaterThanOrEqual(1); | 
					
						
							|  |  |  |     expect(0).not.toBeGreaterThanOrEqual(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(1n).toBeGreaterThanOrEqual(0n); | 
					
						
							|  |  |  |     expect(1n).toBeGreaterThanOrEqual(1n); | 
					
						
							|  |  |  |     expect(0n).not.toBeGreaterThanOrEqual(1n); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         ["foo", 0], | 
					
						
							|  |  |  |         [0, "foo"], | 
					
						
							|  |  |  |         [0, 0n], | 
					
						
							|  |  |  |         [0n, 0], | 
					
						
							|  |  |  |     ].forEach(arr => { | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             expect(arr[0]).toBeGreaterThanOrEqual(arr[1]); | 
					
						
							|  |  |  |         }).toThrow(ExpectationError); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-04 10:09:48 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | test("toContain", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect([1, 2, 3]).toContain(1); | 
					
						
							|  |  |  |     expect([1, 2, 3]).toContain(2); | 
					
						
							|  |  |  |     expect([1, 2, 3]).toContain(3); | 
					
						
							|  |  |  |     expect([{ foo: 1 }]).not.toContain({ foo: 1 }); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toContainEqual", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect([1, 2, 3]).toContainEqual(1); | 
					
						
							|  |  |  |     expect([1, 2, 3]).toContainEqual(2); | 
					
						
							|  |  |  |     expect([1, 2, 3]).toContainEqual(3); | 
					
						
							|  |  |  |     expect([{ foo: 1 }]).toContainEqual({ foo: 1 }); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toEqual", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(undefined).toEqual(undefined); | 
					
						
							|  |  |  |     expect(null).toEqual(null); | 
					
						
							|  |  |  |     expect(undefined).not.toEqual(null); | 
					
						
							|  |  |  |     expect(null).not.toEqual(undefined); | 
					
						
							|  |  |  |     expect(NaN).toEqual(NaN); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(1).toEqual(1); | 
					
						
							|  |  |  |     expect("abcd").toEqual("abcd"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let s = Symbol(); | 
					
						
							|  |  |  |     expect(s).toEqual(s); | 
					
						
							|  |  |  |     expect(Symbol()).not.toEqual(Symbol()); | 
					
						
							|  |  |  |     expect(Symbol.for("foo")).toEqual(Symbol.for("foo")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect({ foo: 1, bar: { baz: [1, 2, 3] } }).toEqual({ foo: 1, bar: { baz: [1, 2, 3] } }); | 
					
						
							|  |  |  |     expect([1, 2, { foo: 1 }, [3, [4, 5]]]).toEqual([1, 2, { foo: 1 }, [3, [4, 5]]]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function foo() {} | 
					
						
							|  |  |  |     expect(foo).toEqual(foo); | 
					
						
							|  |  |  |     expect(function () {}).not.toEqual(function () {}); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toThrow", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(() => {}).not.toThrow(); | 
					
						
							|  |  |  |     expect(() => {}).not.toThrow("foo"); | 
					
						
							|  |  |  |     expect(() => {}).not.toThrow(TypeError); | 
					
						
							|  |  |  |     expect(() => {}).not.toThrow(new TypeError("foo")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let thrower = () => { | 
					
						
							|  |  |  |         throw new TypeError("foo bar"); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(thrower).toThrow(); | 
					
						
							|  |  |  |     expect(thrower).toThrow(TypeError); | 
					
						
							|  |  |  |     expect(thrower).toThrow("o ba"); | 
					
						
							|  |  |  |     expect(thrower).toThrow("foo bar"); | 
					
						
							|  |  |  |     expect(thrower).not.toThrow("baz"); | 
					
						
							|  |  |  |     expect(thrower).not.toThrow(ReferenceError); | 
					
						
							|  |  |  |     expect(thrower).toThrow(new TypeError("foo bar")); | 
					
						
							|  |  |  |     expect(thrower).not.toThrow(new TypeError("o ba")); | 
					
						
							|  |  |  |     expect(thrower).toThrow(new ReferenceError("foo bar")); | 
					
						
							|  |  |  |     expect(thrower).toThrow({ message: "foo bar" }); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("pass", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect().pass(); | 
					
						
							|  |  |  |     expect({}).pass(); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("fail", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     // FIXME: Doesn't really make sense; this is a great candidate
 | 
					
						
							|  |  |  |     // for expect.assertions()
 | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |         expect().fail(); | 
					
						
							|  |  |  |     } catch (e) { | 
					
						
							|  |  |  |         expect(e.name).toBe("ExpectationError"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toThrowWithMessage", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let incorrectUsages = [ | 
					
						
							|  |  |  |         [1, undefined, undefined], | 
					
						
							|  |  |  |         [() => {}, undefined, undefined], | 
					
						
							|  |  |  |         [() => {}, function () {}, undefined], | 
					
						
							|  |  |  |         [() => {}, undefined, "test"], | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     incorrectUsages.forEach(arr => { | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             expect(arr[0]).toThrowWithMessage(arr[1], arr[2]); | 
					
						
							|  |  |  |         }).toThrow(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let thrower = () => { | 
					
						
							|  |  |  |         throw new TypeError("foo bar"); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(thrower).toThrowWithMessage(TypeError, "foo bar"); | 
					
						
							|  |  |  |     expect(thrower).toThrowWithMessage(TypeError, "foo"); | 
					
						
							|  |  |  |     expect(thrower).toThrowWithMessage(TypeError, "o ba"); | 
					
						
							|  |  |  |     expect(thrower).not.toThrowWithMessage(ReferenceError, "foo bar"); | 
					
						
							|  |  |  |     expect(thrower).not.toThrowWithMessage(TypeError, "foo baz"); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // FIXME: Will have to change when this matcher changes to use the
 | 
					
						
							|  |  |  | // "eval" function
 | 
					
						
							|  |  |  | test("toEval", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect("let a = 1").toEval(); | 
					
						
							|  |  |  |     expect("a < 1").not.toEval(); | 
					
						
							|  |  |  |     expect("&&*^%#%@").not.toEval(); | 
					
						
							|  |  |  |     expect("function foo() { return 1; }; return foo();").toEval(); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // FIXME: Will have to change when this matcher changes to use the
 | 
					
						
							|  |  |  | // "eval" function
 | 
					
						
							|  |  |  | test("toEvalTo", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect("let a = 1").toEvalTo(); | 
					
						
							|  |  |  |     expect("let a = 1").toEvalTo(undefined); | 
					
						
							|  |  |  |     expect("return 10").toEvalTo(10); | 
					
						
							|  |  |  |     expect("return 10").not.toEvalTo(5); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(() => { | 
					
						
							|  |  |  |         expect("*^&%%").not.toEvalTo(); | 
					
						
							|  |  |  |     }).toThrow(); | 
					
						
							| 
									
										
										
										
											2020-07-03 18:09:35 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | test("toHaveConfigurableProperty", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect({ foo: 1 }).toHaveConfigurableProperty("foo"); | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(() => { | 
					
						
							|  |  |  |         expect({ foo: 1 }).not.toHaveConfigurableProperty("bar"); | 
					
						
							|  |  |  |     }).toThrow(); | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let o = {}; | 
					
						
							|  |  |  |     Object.defineProperty(o, "foo", { configurable: true, value: 1 }); | 
					
						
							|  |  |  |     Object.defineProperty(o, "bar", { configurable: false, value: 1 }); | 
					
						
							|  |  |  |     expect(o).toHaveConfigurableProperty("foo"); | 
					
						
							|  |  |  |     expect(o).not.toHaveConfigurableProperty("bar"); | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toHaveEnumerableProperty", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect({ foo: 1 }).toHaveEnumerableProperty("foo"); | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(() => { | 
					
						
							|  |  |  |         expect({ foo: 1 }).not.toHaveEnumerableProperty("bar"); | 
					
						
							|  |  |  |     }).toThrow(); | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let o = {}; | 
					
						
							|  |  |  |     Object.defineProperty(o, "foo", { enumerable: true, value: 1 }); | 
					
						
							|  |  |  |     Object.defineProperty(o, "bar", { enumerable: false, value: 1 }); | 
					
						
							|  |  |  |     expect(o).toHaveEnumerableProperty("foo"); | 
					
						
							|  |  |  |     expect(o).not.toHaveEnumerableProperty("bar"); | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toHaveWritableProperty", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect({ foo: 1 }).toHaveWritableProperty("foo"); | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(() => { | 
					
						
							|  |  |  |         expect({ foo: 1 }).not.toHaveWritableProperty("bar"); | 
					
						
							|  |  |  |     }).toThrow(); | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let o = {}; | 
					
						
							|  |  |  |     Object.defineProperty(o, "foo", { writable: true, value: 1 }); | 
					
						
							|  |  |  |     Object.defineProperty(o, "bar", { writable: false, value: 1 }); | 
					
						
							|  |  |  |     expect(o).toHaveWritableProperty("foo"); | 
					
						
							|  |  |  |     expect(o).not.toHaveWritableProperty("bar"); | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toHaveGetterProperty", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(() => { | 
					
						
							|  |  |  |         expect({ foo: 1 }).not.toHaveGetterProperty("bar"); | 
					
						
							|  |  |  |     }).toThrow(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let o = {}; | 
					
						
							|  |  |  |     Object.defineProperty(o, "foo", { | 
					
						
							|  |  |  |         get() { | 
					
						
							|  |  |  |             return 1; | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     Object.defineProperty(o, "bar", { value: 1 }); | 
					
						
							|  |  |  |     expect(o).toHaveGetterProperty("foo"); | 
					
						
							|  |  |  |     expect(o).not.toHaveGetterProperty("bar"); | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("toHaveSetterProperty", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(() => { | 
					
						
							|  |  |  |         expect({ foo: 1 }).not.toHaveSetterProperty("bar"); | 
					
						
							|  |  |  |     }).toThrow(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let o = {}; | 
					
						
							|  |  |  |     Object.defineProperty(o, "foo", { set(_) {} }); | 
					
						
							|  |  |  |     Object.defineProperty(o, "bar", { value: 1 }); | 
					
						
							|  |  |  |     expect(o).toHaveSetterProperty("foo"); | 
					
						
							|  |  |  |     expect(o).not.toHaveSetterProperty("bar"); | 
					
						
							| 
									
										
										
										
											2020-07-03 23:13:06 -07:00
										 |  |  | }); |