mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 17:57:23 +01:00
Fix an issue where beforeEach/afterEach functions were called on other describe blocks with the same name
This commit is contained in:
@ -51,3 +51,78 @@ describe('with expectations', function () {
|
||||
|
||||
test('test', function () {});
|
||||
});
|
||||
|
||||
describe('matching describe block names', function () {
|
||||
beforeEach(function () {
|
||||
$this->foo = 1;
|
||||
});
|
||||
|
||||
describe('outer', function () {
|
||||
beforeEach(function () {
|
||||
$this->foo++;
|
||||
});
|
||||
|
||||
describe('middle', function () {
|
||||
beforeEach(function () {
|
||||
$this->foo++;
|
||||
});
|
||||
|
||||
describe('inner', function () {
|
||||
beforeEach(function () {
|
||||
$this->foo++;
|
||||
});
|
||||
|
||||
it('should call all parent beforeEach functions', function () {
|
||||
expect($this->foo)->toBe(4);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('middle', function () {
|
||||
it('should not call beforeEach functions for sibling describe blocks with the same name', function () {
|
||||
expect($this->foo)->toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('inner', function () {
|
||||
it('should not call beforeEach functions for descendent of sibling describe blocks with the same name', function () {
|
||||
expect($this->foo)->toBe(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$matchingNameCalls = 0;
|
||||
describe('matching name', function () use (&$matchingNameCalls) {
|
||||
beforeEach(function () use (&$matchingNameCalls) {
|
||||
$matchingNameCalls++;
|
||||
});
|
||||
|
||||
it('should call the before each', function () use (&$matchingNameCalls) {
|
||||
expect($matchingNameCalls)->toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('matching name', function () use (&$matchingNameCalls) {
|
||||
it('should not call the before each on the describe block with the same name', function () use (&$matchingNameCalls) {
|
||||
expect($matchingNameCalls)->toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
$this->baz = 1;
|
||||
});
|
||||
|
||||
describe('called on all tests', function () {
|
||||
beforeEach(function () {
|
||||
$this->baz++;
|
||||
});
|
||||
|
||||
test('beforeEach should be called', function () {
|
||||
expect($this->baz)->toBe(2);
|
||||
});
|
||||
|
||||
test('beforeEach should be called for all tests', function () {
|
||||
expect($this->baz)->toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user