Giter Site home page Giter Site logo

Comments (2)

mattphillips avatar mattphillips commented on September 27, 2024

Hey @dainchatel I suspect the issue is because when each is being evaluated the products array is still undefined.

I've knocked up a quick example in a Jest repl here

The example just uses log statements instead of each

describe('test suite', () => {
  let products

  beforeAll(() => {
    products = [['def', '321'], ['abc', '123']]
  })

  describe('in here now', () => {
    console.log('No products', products)
    
    test('this should log the products', () => {
      console.log('Products:', products);
    })
  })
})

As you will see when you run the repl the outer log with be undefined with the one inside of the test being the actual array. This is because Jest is internally preventing the execution of the test callback function until the beforeAll is run.

It appears that the inner describe callback is evaluated immediately but not the nested tests which means the console.log or each function is also evaluated immediately so we are unable to wait on the global setup hooks (beforeAll etc).

I'm not sure there is a way around this unfortunately.

It might be worth asking a question in a core Jest channel to see if a describe block should wait for the beforeAll to finish before being executed?

from jest-each.

dainchatel avatar dainchatel commented on September 27, 2024

thanks, @mattphillips! I really appreciate your answer. I came to the same conclusion, and may go see what the main jest channel has to say about whether nested describe blocks should wait for a beforeAll. But for deadline's sake, just ended up loading my products synchronously. Since it's not an issue with jest-each I will close. Thanks again-

from jest-each.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.