Mocking allows our tests to be deterministic and ensure that we will get the expected result every time.

The most naïve approach to mocking in JavaScript is to override an object’s properties in the test. This is pretty simple and straightforward, but also fairly limited. In this lesson, we’ll monkey patch our getWinner function to always return the same winner every time the function is called. After the test is run, we’ll clean up the mock and assign the original function implementation back to getWinner.