protractor icon indicating copy to clipboard operation
protractor copied to clipboard

How to specify a reason after expect FAILS

Open mohit-excelindia opened this issue 12 years ago • 7 comments

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

mohit-excelindia avatar Mar 03 '14 06:03 mohit-excelindia

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 avatar Mar 03 '14 19:03 juliemr

@juliemr - Would it possible to specify reason on failure than logging line number on the stack trace ?.

smahalingam avatar Mar 05 '14 11:03 smahalingam

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 avatar Mar 05 '14 11:03 mohit-excelindia

@mohit-excelindia - I agree

smahalingam avatar Mar 05 '14 14:03 smahalingam

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/

juliemr avatar Mar 05 '14 18:03 juliemr

Closing this since line numbers are in and it's a Jasmine issue which could be solved with custom matchers.

juliemr avatar Mar 27 '14 23:03 juliemr

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.

mohit-excelindia avatar Mar 28 '14 04:03 mohit-excelindia