javascript - What is the purpose of Mocha's before() function? -


There are several "hooks" to run collaborative functionality in a separate test for testing in Mocha (to clean itself For making fake files, etc.).

However, before () ( not first () , that one I get), it seems very redundant

> Logic triggers once , why do I need to wrap it in the function even before all tests in the current suit? << P>

There is no difference between the following:

  Description ('some', function () (before (doSomePreTestLogic); // test Ahoy});   

and

  Description ('some', function () {doSomePreTestLogic ( ); // Test Ahoy});   

 
  before ?   

semantics

semantique

This is probably the biggest one Sometimes you may need to do one thing, such as populating some dummy data in your database, before running the actual database. You can certainly do this in testing, but it throws your reporting. If you were to pre-populating E error occurs, and before the run all terms of the actual exam.

Cleaner for Async Test P>

Mocha Tests can be asynchronous, so your first () might be a hook logic. Returning to pre-populations example is easy because it means that all your ASINCC Pre-Test Logic will not inspire any other level indentation on all your actual test logic.

Integration with other hooks:

Mocha also offers several other hooks, namely: after () , beforeEach () , and afterEach () . You probably can ask the same question about all these other hooks, but if you buy in this belief that any of these is a valid existence, then first () Need to be included in the API.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -