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!
The JS engine evaluates
obj.methodbefore it is even passed to theexpectfunction. 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