question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

execution order difference between jest-jasmine2 and jest-circus

See original GitHub issue

🐛 Bug Report

https://jestjs.io/docs/en/setup-teardown#order-of-execution-of-describe-and-test-blocks manual says execution order of describe and test blocks should be

describe('outer', () => {
  console.log('describe outer-a');

  describe('describe inner 1', () => {
    console.log('describe inner 1');
    test('test 1', () => {
      console.log('test for describe inner 1');
      expect(true).toEqual(true);
    });
  });

  console.log('describe outer-b');

  test('test 1', () => {
    console.log('test for describe outer');
    expect(true).toEqual(true);
  });

  describe('describe inner 2', () => {
    console.log('describe inner 2');
    test('test for describe inner 2', () => {
      console.log('test for describe inner 2');
      expect(false).toEqual(false);
    });
  });

  console.log('describe outer-c');
});

// describe outer-a
// describe inner 1
// describe outer-b
// describe inner 2
// describe outer-c
// test for describe inner 1
// test for describe outer
// test for describe inner 2

while this is true for jest-jasmine2 In jest-circus, it is not work as expected

 PASS  test.js
  outer
    ✓ test 1 (16ms)
    describe inner 1
      ✓ test 1 (3ms)
    describe inner 2
      ✓ test for describe inner 2 (6ms)

  console.log test.js:2
    describe outer-a

  console.log test.js:5
    describe inner 1

  console.log test.js:12
    describe outer-b

  console.log test.js:20
    describe inner 2

  console.log test.js:27
    describe outer-c

  console.log test.js:15
    test for describe outer

  console.log test.js:7
    test for describe inner 1

  console.log test.js:22
    test for describe inner 2

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        2.371s

To Reproduce

Just use same source in manual with jest-jasmine2 or jest-circus

Expected behavior

execution order must be same

Link to repl or repo (highly encouraged)

none

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jeysalcommented, May 3, 2020

Currently implementing this, slightly scared by the fact that there seems to be no existing test failing because of it 😄 But maybe it makes sense nobody has written this, we’re probably so used to writing order-independent tests that we don’t even think of any execution order as a requirement.

2reactions
viliccommented, Apr 28, 2019

I would prefer the behavior of jasmine2. In my use case I use describe to organize larger tests that can be split, while the order still matters.

E.g.:

# 1
  # 1.1
    * 1.1.1
    * 1.1.2
  * 1.2
* 2

# for describe and * for test.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest 27: New Defaults for Jest, 2021 edition
There may be minor differences in execution order and strictness, but we expect no major upgrade difficulties other than for code relying on ......
Read more >
jest-circus | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Jest/Jasmine: Weird Execution Order Of beforeEach()
[This answer is relevant for both Jest and Jasmine!] The error in the example above is a misunderstanding of how nesting describe ,...
Read more >
jest-repl: Versions | Openbase
[expect] [BREAKING] Differentiate between MatcherContext MatcherUtils and MatcherState types (#13141); [jest-circus] Add support for test.failing.each ...
Read more >
Jest Setup Guide | Detox
The former runner, jest-jasmine2 , is deprecated due to specific bugs in the ... are relevant for jest@^27.0.0 (and jest@^26.0.1 + jest-circus@^26.0.1 )....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found