jest: #5585 breaks pre-established "beforeEach" order

When introduced #5885, the order of beforeEachs was inverted. Take the following test for instance:

describe('test', () => {
  beforeEach(() => {
    console.log('BeforeEach');
  });

  it('foo', () => {
    console.log('It Foo');

    beforeEach(() => {
      console.log('BeforeEach Inline Foo');
    });
  });

  it('bar', () => {
    console.log('It Bar');

    beforeEach(() => {
      console.log('BeforeEach Inline Bar');
    });
  });
});

The order should be:

BeforeEach
It Foo
BeforeEach Inline Foo
BeforeEach
It Bar

But it is instead:

BeforeEach
It Foo
BeforeEach
BeforeEach Inline Foo
It Bar

One might argue about beforeEachs inside its, but the reality is that this is supported and the current order is altered. We need to get some sort of fix or rather revert the PR.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (14 by maintainers)

Commits related to this issue

Most upvoted comments

@mjesun Oh man, I thought testing it internally meant you’ll do it 😉 So once again we misunderstood each other. Here’s a PR: https://github.com/facebook/jest/pull/6006

Looking forward to seeing it that fixes the issue.

Oh, I was waiting for the change 😅I need to merge and create alpha.7, then I can test it internally. I agree it was confusing 🙂

I’m OK with moving the wrapChildren to the outer scope; I can also perform a quick test with your change internally and see if everything results in the expected behavior. 🙂

We could also parametrize it for the top-suite case so its evaluated early, but I don’t think keeping inconsistent behavior is the way to go.

No, you are right, whatever the behavior is, it should always be the same.

@rickhanlonii this is in the latest alpha only.