Skip to content

Using Mocha, Chai, Supertest and Express test your TODO endpoint

Notifications You must be signed in to change notification settings

wdi-sg/mocha-todo-list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

Testing TODOs with Mocha/Chai Lab

This is Part 3.1 (optional) of a series of labs working towards building your first full stack web app.

Introduction

Note: This can be a pair programming activity or done independently.

Now that we've written a few tests in our Express application, let's practice writing tests for a more complex application, our TODO list, an app that uses Mongo.

Exercise

Requirements

  • Setup the app to run mocha, chai and supertest
  • Implement these tests:
GET /todos
  ✓ should return a 200 response
  ✓ should return an array
  ✓ should return all the records in the database

GET /todos/:id
  ✓ should return a 200 response
  ✓ should return an object containing the fields 'name', 'description' and 'completed'

POST /todos
  ✓ should return a 200 response
  ✓ should return a 422 response if the field name is wrong
  ✓ should return an error message if the name field is wrong
  ✓ should add a new todo to the database

PUT /todos/:id
  ✓ should return a 200 response
  ✓ should update a todo document

DELETE /todos/:id
  ✓ should remove a todo document
  • If you include the model todo in your spec file, you can execute requests to MongoDB directly from the test file, allowing you to watch the database directly before or after an action made by a test

Bonus:

  • Add more validations in the models and add the tests for them, too
  • Add fields with different datatypes and write tests for them

Starter code

No starter code... use the output of the previous Express Todo Lab.

Deliverable

You should expect something like this in the terminal:

CLI Chai output

Additional Resources

About

Using Mocha, Chai, Supertest and Express test your TODO endpoint

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published