Coder Social home page Coder Social logo

mocha-todo-list's Introduction

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

mocha-todo-list's People

Contributors

jeremiahalex avatar nickangtc avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.