O'Reilly logo

Express.js Blueprints by Ben Augarten, Marc Kuo, Eric Lin, Aidha Shaikh, Fabiano Pereira Soriani, Geoffrey Tisserand, Chiqing Zhang, Kan Zhang

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining routes

Let's start by defining the first routes we need and how we want them to behave and simple logical steps building what's strictly essential first, in a TDD style.

  1. The first thing is that we need users to be able to register; the smallest test case to register our user is as follows:
    '''javascript
    var dbCleanup = require('./utils/db')
    var expect = require('chai').expect;
    var request = require('supertest');
    var app = require('../src/app');
    
    describe('Registration', function() {
      it("shoots a valid request", function(done){
        var user = {
          'email': 'supertest'+Math.random()+'@example.com',
          'name': 'Super'+Math.random(),
        };
    
        request(app)
          .post('/register')
          .send(user)
          .expect(200, done);
      })
    })
  2. Assuming you have Mocha installed with npm i -g ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required