toHaveProperty
Asserts that the value is an object that includes a property with given name (using the
in
operator).
toHaveProperty(propertyName: string): Assertion<unknown>
Notes
- This method also succeeds for properties that are defined on the object’s prototype.
Return value
A new assertion for the value of the property, which can be evaluated using further Assertion methods.
Example
// assert the value of a property, checking that it exists first:
let obj = { foo: "bar" };
expect(obj).toHaveProperty("foo").toBe("bar");
Related
- class AssertionRepresents a value ready to be asserted.
- toHaveMethod(methodName)Asserts that the value is an object that includes a function property with given name.