Node.js 摩卡咖啡-每次之前还是之前,哪一种先开始?
我有一个web应用程序,其规格如下:Node.js 摩卡咖啡-每次之前还是之前,哪一种先开始?,node.js,express,mocha.js,Node.js,Express,Mocha.js,我有一个web应用程序,其规格如下: describe('Hook them up', () => { var server; beforeEach(done => { server = app.listen(done); }); before(done => { // Does this run before or after "beforeEach" // If I try to access
describe('Hook them up', () => {
var server;
beforeEach(done => {
server = app.listen(done);
});
before(done => {
// Does this run before or after "beforeEach"
// If I try to access the api at this point I get an ECONNREFUSED
});
after(done => {
server.close(done);
});
it('should set the \'createdAt\' property for \'DndUsers\' objects', done => {
api.post('/api/tweets')
.send({ text: 'Hello World' })
.then(done)
.catch(err => {
console.log(err);
done();
});
});
});
在我的另一个项目中,如果我尝试在before
块中访问api,它工作正常,就好像每个之前的已经运行过一样。回答了一个非常类似的问题
Mocha的test runner以世界上最好的方式解释了这一功能
从钩子部分:
describe('hooks', function() {
before(function() {
// runs before all tests in this block
});
after(function() {
// runs after all tests in this block
});
beforeEach(function() {
// runs before each test in this block
});
afterEach(function() {
// runs after each test in this block
});
// test cases
it(...); // Test 1
it(...); // Test 2
});
您可以将这些例程嵌套在其他descripe块中,这些块也可以具有before/beforeach例程
这应该给你
hooks
before
beforeEach
Test 1
afterEach
beforeEach
Test 2
afterEach
after