-
-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for nested describe blocks #1295
Conversation
@jshayes honestly, looks solid. do you mind to add a few more tests? specially around stuff like chaining methods after describe blocks, hooks, etc... |
@nunomaduro I added some more test. Let me know if there are any cases you think I missed that you would like tested. |
I would LOVE this. Having no support for nested |
src/PendingCalls/AfterEachCall.php
Outdated
@@ -54,7 +54,7 @@ public function __destruct() | |||
$proxies = $this->proxies; | |||
|
|||
$afterEachTestCase = ChainableClosure::boundWhen( | |||
fn (): bool => is_null($describing) || $this->__describing === $describing, | |||
fn (): bool => $describing === [] || in_array(end($describing), $this->__describing, true), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
end() advances array's internal pointer to the last element, and returns its value.
Because this function actually mutates the given value, i rather not use it.
@@ -11,11 +11,15 @@ trait Describable | |||
{ | |||
/** | |||
* Note: this is property is not used; however, it gets added automatically by rector php. | |||
* | |||
* @var string[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use the format array<int, string>
instead.
@@ -24,6 +24,10 @@ | |||
↓ it may have an associated PR #1 | |||
↓ it may have an associated note | |||
// a note | |||
↓ todo on describe → todo block → nested inside todo block → it should not execute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests too in the middle of the test file?
@@ -24,6 +24,10 @@ | |||
↓ it may have an associated PR #1 | |||
↓ it may have an associated note | |||
// a note | |||
↓ todo on describe → todo block → nested inside todo block → it should not execute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests too in the middle of the test file?
@@ -178,6 +183,10 @@ | |||
✓ it may be used with high order with dataset "informal" | |||
✓ it may be used with high order even when bound with dataset "formal" | |||
✓ it may be used with high order even when bound with dataset "informal" | |||
✓ with on nested describe → nested → before inner describe block with (1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests too in the middle of the test file?
@@ -188,6 +197,12 @@ | |||
✓ depends run test only once | |||
✓ it asserts true is true | |||
✓ depends works with the correct test name | |||
✓ describe block → first in describe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests too in the middle of the test file?
// This is a runtime note within describe | ||
✓ nested → describe nested within describe → it may have a static note and runtime note |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests too in the middle of the test file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a test after this one: multiple notes
, let me know if you want other tests here as well
@@ -1255,6 +1301,12 @@ | |||
- it skips when skip after assertion | |||
- it can use something in the test case as a condition → This test was skipped | |||
- it can user higher order callables and skip | |||
- skip on describe → skipped tests → nested inside skipped block → it should not execute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests too in the middle of the test file?
@@ -1285,6 +1337,12 @@ | |||
↓ it may have an associated PR #1 | |||
↓ it may have an associated note | |||
// a note | |||
↓ todo on describe → todo block → nested inside todo block → it should not execute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests too in the middle of the test file?
I added some more tests to the end of the test files, after the describe blocks. Is this what you had in mind? |
Also, I noticed another issue with describe blocks that I have a separate PR for, but I think the issue is a bigger deal due do to nested describe blocks in this PR. For instance, the following test describe('same-name', function () {
beforeEach(function () {
var_dump('before each');
});
});
describe('same-name', function () {
test('test', function () {
expect(true)->toBeTrue();
});
}); Will produce the following output
Since it is just checking the name of the describe block, it will match the before each from one block into another block. I do have a PR where I address this issue, however I figured I'd bring it up here because this could have some implications on nested describe blocks until the issue is resolved. For instance, the following test describe('outer block 1', function () {
describe('same-name', function () {
beforeEach(function () {
var_dump('before each');
});
});
});
describe('outer block 2', function () {
describe('same-name', function () {
test('test', function () {
expect(true)->toBeTrue();
});
});
}); will produce the following output
This is the current behaviour, before my changes here, but I think this is a fairly common use case to have describe blocks with the same name when they are nested in different describe blocks. Anyway, let me know if you are okay with this being a separate PR, or if you want me to add those changes here. |
What:
Description:
Calls parent beforeEach and afterEach functions in nested describe blocks. Also updates the test names to handle multiple nested describe blocks.
Given the following test, here is the output before and after this change
Before
After
This change could cause breaking changes, so I'm not sure what you think of this. Since this project follows semver, I suppose this should go towards version 4.
Related:
#1023
#1138
This change was based off #1294, so it includes those changes as well, since they were required for this change.