【发布时间】:2019-10-14 03:57:08
【问题描述】:
我想创建一个在before Hook 之前执行的beforeEach Hook。
基本上我想要以下行为:
beforeEach(() => {
console.log('beforeEach')
})
describe('tests', () => {
before(() => {
console.log('before')
})
it('test 1', () => {
console.log('it')
})
})
我得到:
before
beforeEach
it
但我想要的输出是:
beforeEach
before
it
获得所需行为的正确结构是什么?
解决方法
目前我找到了使用两个嵌套 beforeEach 的解决方法:
beforeEach(() => {
console.log('beforeEach1')
})
describe('tests', () => {
beforeEach(() => {
console.log('beforeEach2')
})
it('test 1', () => {
console.log('it')
})
})
哪个输出是:
beforeEach1
beforeEach2
it
【问题讨论】:
标签: javascript node.js mocha.js