This video is available to students only

Exercise 1 (Testing for Hash Password Functions)

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

Previous LessonNaming and organizing testsNext LessonExercise 1 solution (Testing for Hash Password Functions)

Lesson Transcript

  • [00:00 - 00:07] Here's an exciting exercise. In this exercise, you'll write a unit test for the hash password function.

  • [00:08 - 00:24] The goal is to observe the entry and exit points of this function and write a unit test based on your observation. The hash password function takes a password as input and returns a hash to version of that password.

  • [00:25 - 00:36] Our task is to write a unit test that verifies the correct behavior of this function. It's important to note that the hash password function is asynchronous.

  • [00:37 - 00:53] Therefore, the function that houses the test logic needs to be asynchronous as well. To properly test an asynchronous function, we need to await the return value of the function before making our assertions.

  • [00:54 - 01:09] This ensures that the test waits for the asynchronous function to complete before proceeding. By following these guidelines, you can effectively test the hash password function and ensure it behaves as expected.

  • [01:10 - 01:17] Don't forget to use the appropriate naming framework. Either given when then or the use naming framework.

  • [01:18 - 01:29] Also, use the arrange act as a set pattern. Get ready to dive into this exercise and put your newly acquired skills to the test.

  • [01:30 - 01:36] Remember to create an asynchronous test function, await the return of the hash password function and make your assertions. Happy testing!

This lesson preview is part of the Pain Free Mocking with Jest course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

Unlock This Course

Get unlimited access to Pain Free Mocking with Jest, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course Pain Free Mocking with Jest