Fix an issue where beforeEach/afterEach functions were called on other describe blocks with the same name

This commit is contained in:
jshayes
2024-10-12 01:06:16 -04:00
parent 709ecb1ba2
commit b5b8fab09b
17 changed files with 1443 additions and 86 deletions

View File

@ -125,6 +125,74 @@ describe('skip on beforeEach', function () {
});
});
describe('matching describe with skip', function () {
beforeEach(function () {
$this->ran = false;
});
afterEach(function () {
match ($this->name()) {
'__pest_evaluable__matching_describe_with_skip__→__describe_block__→_it_should_not_execute' => expect($this->ran)->toBe(false),
'__pest_evaluable__matching_describe_with_skip__→__describe_block__→_it_should_execute_a_test_in_a_describe_block_with_the_same_name_as_a_skipped_describe_block' => expect($this->ran)->toBe(true),
'__pest_evaluable__matching_describe_with_skip__→_it_should_execute' => expect($this->ran)->toBe(true),
default => $this->fail('Unexpected test name: '.$this->name()),
};
});
describe('describe block', function () {
it('should not execute', function () {
$this->ran = true;
$this->fail();
});
})->skip();
describe('describe block', function () {
it('should execute a test in a describe block with the same name as a skipped describe block', function () {
$this->ran = true;
});
});
it('should execute', function () {
$this->ran = true;
expect($this->ran)->toBe(true);
});
});
describe('matching describe with skip on beforeEach', function () {
beforeEach(function () {
$this->ran = false;
});
afterEach(function () {
match ($this->name()) {
'__pest_evaluable__matching_describe_with_skip_on_beforeEach__→__describe_block__→_it_should_not_execute' => expect($this->ran)->toBe(false),
'__pest_evaluable__matching_describe_with_skip_on_beforeEach__→__describe_block__→_it_should_execute_a_test_in_a_describe_block_with_the_same_name_as_a_skipped_describe_block' => expect($this->ran)->toBe(true),
'__pest_evaluable__matching_describe_with_skip_on_beforeEach__→_it_should_execute' => expect($this->ran)->toBe(true),
default => $this->fail('Unexpected test name: '.$this->name()),
};
});
describe('describe block', function () {
beforeEach()->skip();
it('should not execute', function () {
$this->ran = true;
$this->fail();
});
});
describe('describe block', function () {
it('should execute a test in a describe block with the same name as a skipped describe block', function () {
$this->ran = true;
});
});
it('should execute', function () {
$this->ran = true;
expect($this->ran)->toBe(true);
});
});
it('does not skip after the describe block', function () {
expect(true)->toBeTrue();
});