jest-extended icon indicating copy to clipboard operation
jest-extended copied to clipboard

add an expectAll feature

Open RomainBitard opened this issue 5 years ago • 2 comments

🚀 Feature Proposal

As a developper I want my test to be able to fail on multiple expects so that I can debug/test faster (I posted an issue on jest and copy pasted the same issue there based on a comment stating that it may have it's place here.

it's the same description but here it is : https://github.com/facebook/jest/issues/9638)

Example

It would work like the assertAll in Junit5

assertAll("Should` return address of Oracle's headquarter",
    () -> assertEquals("Redwood Shores", address.getCity()),
    () -> assertEquals("Oracle Parkway", address.getStreet()),
    () -> assertEquals("500", address.getNumber())
);

instead of :

expect(true).toBe(false); // test runner report only this line as a failure
expect(true).toBe(false);

I suggest :

expectAll( 
   () => expect(true).toBe(false), // test runner report this line as a failure
   () => expect(true).toBe(false) // test runner report this line as a failure
)

Jest is awesome and with this QOL improvement it would enhance developpers productivity even more

RomainBitard avatar Mar 07 '20 12:03 RomainBitard

I feel this is a legit feature request for jest ! Not so much for this jest-extended library, which aims to support matchers, while this is more a core jest assertion bubbling modification request.

Having used this effectively and extensively in Junit5 - assertAll, it is really a better user experience to not have to fix one error at a time and instead! 😄

API REQ: expectAll

Asserts that all supplied executables do not throw an (Assertion) Error.

If any of the supplied executable throws an AssertionError, all remaining executables should still be executed, and all failures can be aggregated and reported in a MultipleFailuresError.

Else if an executable throws an exception that is not an AssertionError, execution should halt immediately, and the exception should be re-thrown as is but masked as an UncheckedException.

Bonus:

If Jest does this Error collection more smoother by default for all AssertionErrors within the it block (with some js magic, without an explicitAll assertions), that would also be Awesome!! 😃

ufo2mstar avatar Apr 02 '20 17:04 ufo2mstar

This feature is badly needed :'(

JeanCParis avatar Mar 02 '22 15:03 JeanCParis