0

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

Rory
  • 1,442
  • 4
  • 21
  • 38
  • Have you tried using jasmines async testing features? https://jasmine.github.io/2.0/introduction.html#section-Asynchronous_Support – 0xcaff Nov 29 '16 at 21:18
  • NO, but I've just come across this https://github.com/hyzhak/jasmine-es6-generator – Rory Nov 29 '16 at 21:35
  • That package is 4 lines of code which wraps async tests. https://raw.githubusercontent.com/hyzhak/jasmine-es6-generator/master/index.js – 0xcaff Nov 29 '16 at 21:40
  • yes, just been looking at it – Rory Nov 29 '16 at 21:48
  • this is close: http://stackoverflow.com/questions/35280756/how-do-i-test-nested-es6-generators-using-mocha – Rory Nov 29 '16 at 21:57

0 Answers0