pestphp / pest

Pest is an elegant PHP testing Framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP.
https://pestphp.com
MIT License
9.46k stars 341 forks source link

[Bug]: When nesting describers and the describer parent doesn't have test it will skip the beforeEach #1138

Open hjJunior opened 5 months ago

hjJunior commented 5 months ago

What Happened

Giving the following structure with nested blocks:

beforeEach(fn () => dump('root block called'));

describe('#block1', function () {
  beforeEach(fn() => dump('#block1'));

  describe('#block1->subBlock#1', function () {
    beforeEach(fn() => dump('#block1->subBlock#1'));

    it('testing', function () {});
  });
});

I would expect the beforeEach from #block1 to be executed

How to Reproduce

Example

describe('#block1', function () {
  beforeEach(fn() => dump('#block1'));

  describe('#block1->subBlock#1', function () {
    beforeEach(fn() => dump('#block1->subBlock#1'));

    it('testing', function () {});
  });
});

Sample Repository

No response

Pest Version

2.34.7

PHP Version

8.2.0

Operation System

macOS

Notes

The root beforeEach is executed even when there is no test in same level, you can reproduce it by running the first code provided on "What Happened" section, you will notice that root block called is printed on terminal