Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow fail to work in try/catch #664

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Commits on Oct 9, 2023

  1. Configuration menu
    Copy the full SHA
    d0474ee View commit details
    Browse the repository at this point in the history

Commits on Dec 23, 2023

  1. fix: Use custom reporter to flip expected failures

    To verify that the new `fail` matcher works correctly, we need a way to
    check if the tests failed as expected or not.
    
    Typically one would use `test.failing` for this purpose, but that only
    works if the test threw an exception (e.g. JestException). The `fail`
    matcher does not do this so that it can still work inside `catch`
    blocks.
    
    Instead, we have to hook into the test reporting and mutate the test
    results for our expected test failures prior to usage by other test
    reporters.
    
    This commit creates a custom test reporter which detects tests run in
    the file `fail.test.js` (yes the name is hard-coded) and flips the
    results of tests inside a `.fail` describe block (i.e. our expected
    failures).
     - If the tests failed (expected) we flip the result to a pass.
     - If the tests passed (unexpected) we flip the result to a fail.
    
    The custom reporter also handles the logic for updating the counts for
    failing test suites so that later reporters reflect the actual test
    results correctly.
    thehale committed Dec 23, 2023
    Configuration menu
    Copy the full SHA
    01b1275 View commit details
    Browse the repository at this point in the history