pest icon indicating copy to clipboard operation
pest copied to clipboard

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

Open hjJunior opened this issue 10 months ago • 0 comments

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

  • Create nested blocks with describe, each one having a beforeEach
  • Add any test only on the last child of describe

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

hjJunior avatar Apr 17 '24 22:04 hjJunior