【问题标题】:describe block in test doesn't work as expected测试中的描述块没有按预期工作
【发布时间】:2021-03-05 15:58:44
【问题描述】:

我正在使用摩卡咖啡。


describe('test', async function ()  {
  let a;
  

  before(async () => {
    a = 10;
  })


  it("ff", () => {

  })

  describe("nice", () => {
    const b = a;
    console.log(b);
    it("ss", () => {
      console.log("nice")
    })
  })
})

似乎console.log(b) 打印未定义。即使before 块首先被执行。

任何想法 b 是未定义的而不是 10 吗?

【问题讨论】:

    标签: javascript testing mocha.js chai


    【解决方案1】:

    describe 函数将在调用钩子之前被调用。测试的顺序 (it) 将保留您想要的顺序。例如,在您打印"nice" 的回调中,a 是 10。

    加载测试文件时,Mocha 会执行它的所有套件,并在其中找到(但不执行)任何挂钩和测试。

    来源:https://mochajs.org/#serial-mode(第 8 步)

    【讨论】:

      猜你喜欢
      • 2015-12-26
      • 2016-08-27
      • 1970-01-01
      • 2014-11-22
      • 2021-10-27
      • 2018-05-25
      • 2020-04-21
      • 1970-01-01
      • 2021-03-27
      相关资源
      最近更新 更多