mocha is a JavaScript test framework running on Node.js and in the browser.
Version for this test.
"mocha": "5.1.1"
"node": "9.2.1"
Inside a
describe
, before
will execute **once** before **all tests** inside this describe
including nested tests.
Inside a describe
, beforeEach
will execute **once** before **every test** inside this describe
including nested tests. In other words, if there are **N** tests in total (including nested tests), beforeEach
will execute **N** times in total.
The output is
The outer before(1)
executed once.
The outer beforeEach(1)
executed 5 times, since there are 5 tests(`inner test1`, `inner test2`, `outer test1`, `outer test2`, `outer test3`) in total within the
beforeEach(1)
.
The inner beforeEach(2)
executed twice, since there are 2 tests(`inner test1`, `inner test2`) within the beforeEach(2)
.
Hope this blog could help you understand the before, beforeEach, after, afterEach, it
mocha test.