On Mon, Feb 6, 2012 at 8:04 AM, Jason Smith <j...@iriscouch.com> wrote:
> ## Unit testing
>
> It's imperfect for unit testing; however I think a hypothetical NPM
> package would be fine. It could convert the ddoc functions to
> JavaScript functions in a similar fashion. (Below is the first API
> that popped into my head, no doubt we could make better.)
>
> var assert = require('assert')
>  , couch = require('mock-couchdb')
>
> var ddoc = couch.load_ddoc({views: {people: {map: "function(doc) {
> emit(doc.name, 1) }"}}})
>
> var emitted
> ddoc.on('emit', function(key, val) { emitted = key })
> ddoc.views.people.map({name:"Bob"})
> assert.equal(emitted, "Bob")
>
> --
> Iris Couch

Failing all of that, my personal second choice would be to put all of
those functions in their own CommonJS module.

// map
module.exports = function(doc) {
    var couch = require('couch')
    couch.emit(doc.name, 1)
}

-- 
Iris Couch

Reply via email to