-2

I have two "expect" in my it block and my first it block failed,it still continues the execution and executing the rest of the code in my it block.

My expectation is, if first it block failed, execution stops right there and next it block should get executed.

it ("My se", function() {
expect(true).toBe(false);// it is failing

//my rest of my below code should not get executed.
My functionality code
expect(array[0]).toBe("foo");

});

it ("Second it block", function() {
//Continue the execution
});

Could some please help me with some idea, how i can achieve this. My execution of that particualr it block should stop and the next it should continue.

  • I believe that's the default behaviour, what has made you think you need to do anything? – jonrsharpe Sep 12 '19 at 12:16
  • this is the correct behavior. lets say you click a button and then you expect some message to be changed && an element to appear && another element to not be present anymore. that's why it it should be this way. as per your question there are tons of discussions on internet about this and lots of custom packages that do something like this. Just look it up – Sergey Pleshakov Sep 12 '19 at 16:24
  • Hi Sergey,-- My ask is i need to stop the execution of that particular it block when the expect assertion is failed, rest of the code in that particular it block should not get executed.Next It block should continue to execute. Currently even though expect is failed, the rest of the code in that particular it block continues. I wanted the stop if any expect is failed.Help is much appreciated. – Feroze Gandhi Sep 13 '19 at 05:36

1 Answers1

0

Ideally, expect statement should be the last statement of the it block. You need to update the test in that way to achieve the desired results.

Zohair
  • 268
  • 2
  • 7