全球`之前'和`之前'为摩卡? [英] Global `before` and `beforeEach` for mocha?
本文介绍了全球`之前'和`之前'为摩卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在正在使用mocha进行javascript单元测试。
I'm using mocha for javascript unit-testing now.
我有几个测试文件,每个文件在之前都有一个,而在$之前有
,但它们完全相同。
I have several test files, each file has a before
and beforeEach
, but they are exactly the same.
如何在和<$之前提供全局所有人(或其中一些人)的c $ c> beforeEach
?
推荐答案
宣布一个之前
或
beforeEach
在一个单独的文件中(我使用 spec_helper.coffee
)并要求它。
Declare a before
or beforeEach
in a separate file (I use spec_helper.coffee
) and require it.
spec_helper.coffee
spec_helper.coffee
afterEach (done) ->
async.parallel [
(cb) -> Listing.remove {}, cb
(cb) -> Server.remove {}, cb
], ->
done()
test_something.coffee
test_something.coffee
require './spec_helper'
这篇关于全球`之前'和`之前'为摩卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文