toHaveMethod
Asserts that the value is an object that includes a function property with given name.
toHaveMethod(methodName: string): Assertion<unknown>
Return value
A new assertion for the method, bound to the object, which can be evaluated using further Assertion methods such as toThrowError().
Example
// assert that a method exists and doesn't throw an error:
let s = "foo";
expect(s).toHaveMethod("toUpperCase").not.toThrowError();
Related
- class AssertionRepresents a value ready to be asserted.
- toHaveProperty(propertyName)Asserts that the value is an object that includes a property with given name (using the
in
operator).