Jasmine - Testing for undefined method in object

jasmine, javascript

Solution

The JS engine evaluates `obj.method` before it is even passed to the `expect` function. Hence, there is no way to recover the string `"method"` from within the matcher.

You should write your own matcher that takes the method name as an argument of type string.

Something like

expect(obj).toHaveMethod("method");

Problem

I have a very basic question. How do I check if a method is defined in an object using jasmine? So far I have: ``` expect(obj.method).not.toBeUndefined(); ``` But the report unhelpfully states: ``` 'Expected undefined not to be undefined.' ``` It would be great if, somehow, it could tell me the name of the property I tried looking for in the report. Any advice appreciated!

Original source