How to specify a reason after expect FAILS
Hi @juliemr @wlingke
The suite I have created contains various expects in a single it function. But it becomes very tedious task if one of those it Fails to identify which one has Failed.
For ex.
it('multiple expect in a single it', function(){ expect(condition1).toBe(true); expect(condition2).toBe(true); expect(condition3).toBe(true); });
Now here if any of the expect Fails, it becomes almost impossible to find out which one Failed. Is there anything we can do about it?
Thanks Mohit Gupta
In the coming version stack traces with line numbers will be available for expectation failures, so you'll be able to figure it out from that!
@juliemr - Would it possible to specify reason on failure than logging line number on the stack trace ?.
Also if line number is provided, then time investment in debugging the field will be more. Providing reasons for failure will be a good idea.
@mohit-excelindia - I agree
Unfortunately Jasmine doesn't offer an easy way of doing this. Consider writing a custom matcher - Jasmine has a good writeup of this here: http://pivotallabs.com/writing-beautiful-specs-jasmine-custom-matchers/
Closing this since line numbers are in and it's a Jasmine issue which could be solved with custom matchers.
I found a way to solve my problem,
expect(condition).toBe(true, 'Expected condition was not true');
If expected condition fails, then message attached will get print on the console. I do not know if it is the correct way but nevertheless it was solving my purpose.