Typing out the full mocha command each time can be tiresome. Therefore, we should create an npm script just like we did with the E2E tests. Add the following to the scripts object inside our package.json file:
"test:unit": "mocha 'src/**/*.test.js' --require @babel/register",
Furthermore, let's also update our existing test npm script to run all our tests (both unit and E2E):
"test": "yarn run test:unit && yarn run test:e2e",
Now, we can run our unit tests by running yarn run test:unit, and run all our tests with yarn run test. We have now completed our first unit test, so let's commit the changes and move on to writing even more tests:
$ git add -A && \ git commit -m "Implement first unit test for generateValidationErrorMessage" ...