feat(describe): continues work around hooks

This commit is contained in:
Nuno Maduro
2023-05-26 19:29:46 +01:00
parent 465c65243d
commit 3e8616ec64
11 changed files with 132 additions and 172 deletions

View File

@ -6,56 +6,73 @@ test('before each', function () {
expect($this->count)->toBe(1);
});
describe('describable', function () {
describe('hooks', function () {
beforeEach(function () {
$this->count++;
});
test('basic', function () {
expect(true)->toBeTrue();
});
test('before each', function () {
test('value', function () {
expect($this->count)->toBe(2);
$this->count++;
});
afterEach(function () {
expect($this->count)->toBe(2);
expect($this->count)->toBe(3);
});
});
describe('another describable', function () {
describe('hooks in different orders', function () {
beforeEach(function () {
$this->count++;
});
test('basic', function () {
expect(true)->toBeTrue();
});
test('before each', function () {
expect($this->count)->toBe(2);
test('value', function () {
expect($this->count)->toBe(3);
$this->count++;
});
afterEach(function () {
expect($this->count)->toBe(2);
expect($this->count)->toBe(4);
});
beforeEach(function () {
$this->count++;
});
});
test('should not fail')->todo()->shouldNotRun();
test('todo')->todo()->shouldNotRun();
test('previous describable before each does not get applied here', function () {
expect($this->count)->toBe(1);
});
afterEach(fn () => expect($this->count)->toBe(is_null($this->__describeDescription) ? 1 : 2));
describe('todo', function () {
describe('todo on hook', function () {
beforeEach()->todo();
test('should not fail')->shouldNotRun();
test('should run')->expect(true)->toBeTrue();
});
describe('todo after describe', function () {
describe('todo on describe', function () {
test('should not fail')->shouldNotRun();
test('should run')->expect(true)->toBeTrue();
})->todo();
test('should run')->expect(true)->toBeTrue();
test('with', fn ($foo) => expect($foo)->toBe(1))->with([1]);
describe('with on hook', function () {
beforeEach()->with([2]);
test('value', function ($foo) {
expect($foo)->toBe(2);
});
});
describe('with on describe', function () {
test('value', function ($foo) {
expect($foo)->toBe(3);
});
})->with([3]);