Skip to content

Instantly share code, notes, and snippets.



Last active Dec 16, 2015
What would you like to do?
var should = require('should');
var assert = require('assert');
var request = require('supertest');
var mongoose = require('mongoose');
var winston = require('winston');
var config = require('./config-debug');
describe('Routing', function() {
var url = '';
// within before() you can run all the operations that are needed to setup your tests. In this case
// I want to create a connection with the database, and when I'm done, I call done().
before(function(done) {
// In our tests we use the test db
// use describe to give a title to your test suite, in this case the tile is "Account"
// and then specify a function in which we are going to declare all the tests
// we want to run. Each test starts with the function it() and as a first argument
// we have to provide a meaningful title for it, whereas as the second argument we
// specify a function that takes a single parameter, "done", that we will use
// to specify when our test is completed, and that's what makes easy
// to perform async test!
describe('Account', function() {
it('should return error trying to save duplicate username', function(done) {
var profile = {
username: 'vgheri',
password: 'test',
firstName: 'Valerio',
lastName: 'Gheri'
// once we have specified the info we want to send to the server via POST verb,
// we need to actually perform the action on the resource, in this case we want to
// POST on /api/profiles and we want to send some info
// We do this using the request object, requiring supertest!
// end handles the response
.end(function(err, res) {
if (err) {
throw err;
// this is should.js syntax, very clear
it('should correctly update an existing account', function(done){
var body = {
firstName: 'JP',
lastName: 'Berd'
.expect('Content-Type', /json/)
.expect(200) //Status code
.end(function(err,res) {
if (err) {
throw err;
// Should.js fluent syntax applied'_id');

This comment has been minimized.

Copy link

@zzz6519003 zzz6519003 commented Dec 5, 2014

mocha test.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment