Skip to content

Do child beforeEach() override parent beforeEach() or are they all executed in order? #134

Open

Description

@LeaVerou

Not sure which behavior is best, but whatever hTest implements it should be documented!

On one hand, executing both is probably what most use cases want. On the other hand, then there is no way around it when it's not what you want.

Edit: They override and require this.parent.parent.beforeEach() to invoke the parent with this.parent.beforeEach() causing a stack overflow. Yikes. this.parent should just work. I'm gonna change this to Bug.

Edit 2: Even more mysterious that for beforeAll this.parent works just fine!!

Edit 3: And it apparently requires .call(this) because data doesn't seem to inherit properly?

Activity

  1. added theissue type on May 20, 2026
  2. added 5 commits that reference this issue on May 21, 2026
    765bd99
    4443844
    b19dd87
    fa210ed
    67bd151
  3. DmitrySharabin commented on May 24, 2026

    @DmitrySharabin
    Member

    On one hand, executing both is probably what most use cases want. On the other hand, then there is no way around it when it's not what you want.

    I honestly believe that what we have now is much better than other frameworks suggest. We can define the common behavior on the most appropriate ancestor and tweak it the way you like. Yes, we redefine it by default by adding the same hook on a descendant. And we need to be explicit (and I think that's a good thing; no magic) if we want the ancestor's hook to be executed first (via this.patent.<hook>). But we can do much more than that. We can control where the ancestor's hook should be executed: before our custom actions, after them, or even somewhere in the middle. And that makes complex things possible and simple things easy. So, it's fully aligned with the philosophy we follow.

    whatever hTest implements it should be documented!

    Agreed. I'll do it soon. UPDATE: Done in b6999e8.

    Edit: They override and require this.parent.parent.beforeEach() to invoke the parent with this.parent.beforeEach() causing a stack overflow. Yikes. this.parent should just work. I'm gonna change this to Bug.

    This should go away when we address the more general issue: #147.

    Edit 2: Even more mysterious that for beforeAll this.parent works just fine!!

    I think it's because beforeAll is not inherited. So, we can reference the parent's hook just fine.

    Edit 3: And it apparently requires .call(this) because data doesn't seem to inherit properly?

    It should already be fixed in 0eada46.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions