Working with Jest Mocks

In this project, we are working with the repository layer for an application called Book Club. This application allows users to do the following:

  • Sign up for an account.
  • Maintain a list of books that they want to read and that they have read.
  • Rate and review a book once they have read it.

In addition to maintaining a list of books, the application also shows users a list of the current top 10 best-selling books.

It works great, or so we think. We can’t be sure because we don’t have our tests up and running yet. Using the repository code, we are going to flesh out our test suites and use our mocking skills in the process.

The project is subdivided into the following two groups of tasks:

  • Group 1: Best Seller Repository
    • Task 1: Mocking the Dependency
    • Task 2: Resetting the Implementation
    • Task 3: Creating a Mock for a Successful Method Call
    • Task 4: Creating a Mock for a Failed Method Call
    • Task 5: Running the BestSeller Test Suite
  • Group 2: Book Repository
    • Task 1: Mocking the Dependency
    • Task 2: Creating Mocks For the createBook Function
    • Task 3: Creating Mocks For the getBook Function
    • Task 4: Creating Mocks For the getBooksByUser Function
    • Task 5: Creating Mocks For the updateBook Function
    • Task 6: Creating Mocks For the deleteBook Function
    • Task 7: Running the Book Test Suite