Mocha不遵循文件顺序

时间:2019-08-28 09:24:35

标签: javascript mocha

当我使用mocha运行某些文件时,即使我定义了顺序,它似乎也比其他文件先运行了一些文件。

这里是一个例子:

// init1.js
before(function () {
  console.log('init1 before')
})

after(function () {
  console.log('init1 after')
})

// test1.js
describe('test1', function () {
  it('1', function () {
    console.log('test 1')
  })
})
// init2.js
before(function () {
  console.log('init2 before')
})

after(function () {
  console.log('init2 after')
})
// test2.js
describe('test2', function () {
  it('2', function () {
    console.log('test 2')
  })
})

现在我这样运行:mocha init1 test1 init2 test2,但我得到类似

init1 before
init2 before
  test1
test 1
    ✓ 1

  test2
test 2
    ✓ 2

init1 after
init2 after

我期望的是init2之后的全局挂钩在test1之后而不是之前。

这是预期的行为吗? 有办法实现我的尝试吗?

0 个答案:

没有答案
相关问题