Why can't nested describe() blocks see vars defined in outer blocks?

前端 未结 3 1129
攒了一身酷
攒了一身酷 2021-01-30 20:07

I\'ve run into this issue in real code, but I put together a trivial example to prove the point.

The below code works fine. I\'ve set up a variable in my root desc

3条回答
  •  执念已碎
    2021-01-30 20:28

    The body of a describe block is executed before the beforeEach blocks.

    This is exactly as expected. The problem is that your var trees variable is trying to access orchard before it has been initialized. The body of a describe block is executed before the beforeEach blocks. To solve this problem, the third code snippet is the only way to go.

    Jasmine will first execute the describe blocks, and then execute the beforeEach blocks before running each test.

提交回复
热议问题