Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
Execution of code in other describe blocks - jest

I have the following test setup:

describe(`my tests`, () => {
    describe(`Should not run`, () => {
        console.log(`Should not be printed`);
        describe(`Should also not run`, () => {
            console.log(`Should also not be printed`);
            test(`Then an exception is thrown`, () => {
                console.log(`Should definitely not be printed`);
                throw new Error(`whoops`);
            })
        })

        describe(`Should run`, () => {
            console.log(`Should run`)
            test(`Then I should get this list in the format I expect`, () => {
                console.log(`Should definitely be printed`);
            })
        })

        describe(`Should not run`, () => {
            console.log(`Should not be printed`);
            test(`Then I should get an empty list`, () => {
                throw new Error(`whoops`);
            })
        })
    })
})

When I ask IntelliJ to only run the test case test('Then I should get this list in the format I expect'), I still get the following output:

> Should not be printed
> Should also not be printed
> Should run
> Should not be printed
> Should definitely be printed

Howcome the code of the other describe blocks is being executed? I thought the describe block allowed you to scope test setup so that it only runs for the tests inside that specific block.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Seems that this is the standard and documented behaviour:

Jest executes all describe handlers in a test file before it executes any of the actual tests. This is another reason to do setup and teardown inside before* and after* handlers rather than inside the describe blocks. Once the describe blocks are complete, by default Jest runs all the tests serially in the order they were encountered in the collection phase, waiting for each to finish and be tidied up before moving on.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!