Is before() just for semantic benefit? Why not just set up the player var before the specs w/o wrapping it in before()?
I understand how beforeEach() can be useful but what does before() really do for you? In this example, you can take away the before and simply define the player variable above the specs and they will still have access to it and the test passes.
Gabbie Metheny33,703 Points
Guil doesn't go into it in detail, but in the next video he talks about teardown using
afterEach. These methods can be used to clean up after your tests run. That's not needed in this project, but he's probably introducing it as a best practice since a more complicated project might involve interacting with the DOM or modifying a pretend database.
The big reason (in my eyes) is that because all tests are placed in callbacks, by using
before(), you'll allow the testing framework to make sure things run at the right time. Perhaps not as important for
before() in every case, but critical for other hooks.
Steven Parker207,988 Points
It may make no difference to the running of the test, but if you're establishing conditions specifically for the test it would make sense to set them up in a "before" rather than outside of the test code.
I haven't tried it, but I suspect it would also prevent anything from being added to the global namespace.