Article Image

Nested Describe Blocks Are Now Available in Pest v3.5

Published on: Oct 22 2024
By: Paul Redmond

Pest released v3.5 with support for nested describe() blocks in tests! You can now group related tests inside a parent describe() block, giving you more flexibility in organizing things.

big news: just dropped pest 3.5.0, and it now supports nested describe blocks. happy tuesday, let's go! 🤌🏻 pic.twitter.com/AN2IRJL0pW— Nuno Maduro ☁️ 🦹 (@enunomaduro) 

October 22, 2024

Before this release, you could use the describe() block for group tests; however, you could only do so at the top level of your test file. For example, lets say you want to group all your admin dashboard feature tests together. Before, you might group them in separate top-level describe() blocks, but now you can call describe() inside another describe() like so:

describe('Dashboard', function () {
    beforeEach(fn () => $this->actingAs($this->user));
 
    describe('Notifications', function () {
        test('new notifications are displayed', function () {
            // ...
        });
        test('cleared notifications are no longer visible', function () {
            // ...
        });
    });
 
    describe('New orders', function () {
        test('orders made within the last 24 hours are visible', function () {
            // ...
        });
    });
});

Here's what the output of those grouped tests looks like when you run the test suite. Notice the clean organization of tests:

Update to the latest version to get nested describe blocks as well as all the amazing features available in the release of Pest 3.

Shout out to Justin Hayes, who contributed this support for nested describe blocks in Pull Request #1295!