First here's the db.js
// Load Mongoose interface
var mongoose = require('mongoose');
// Get config file for SQL connection
var connection = mongoose.connect('localhost/test');
// Return connection
module.exports = connection;
Here's the Todo Model, todo.js
// Get mongoose object
var db = require('../lib/db');
// Prepare schema
var schema = new db.Schema(
{
name: String,
description: String
} );
// Return model with schema linked to collection
module.exports = db.model( 'tests', schema );
And here's the route 'update.js' that executes the query against the model
// Require todo model
var Todo = require('../models/todo');
module.exports = function *() {
// Get request body
var input = this.request.body;
// Update todo item with given input ID
yield Todo.update( {_id: input.id}, {
name: input.name,
description: input.description,
created_on: new Date(input.created_on),
updated_on: new Date()});
// Redirect to index
this.redirect('/');
};
The middle ware is koa.js btw. the route being
app.use(route.post('/todo/update', require('./routes/update')));
Question: How do I write a test against 'update.js' that has *() and the yield statement ? What would the Jasmine fake/spy be ?
Any other testing framework will be considered not just Jasmine