node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org ยป



test harness for minq queries

1.0.x of rope targets 1.0.x of minq

test all the things!

According to The complete mink harness video, the best kind of rope to use is nylon.


Experimental: Expect the unexpected. Please provide feedback on api and your use-case.


$ npm install rope

example usage

a mocha-style test given:


var minq = require('minq')

module.exports = function () {
  return minq(process.env.DB).from('foos').toArray().then(function (foos) {
    // sure, we could have used a regex, but imagine more complicated application-level logic that you want to test against known database values
    return foos.filter(function (foo) { return > 3 })


var rope = require('rope')
var moquire = require('moquire')
var chai = require('chai')

describe('foo', function () {
  it('returns names longer than 3 letters', function (done) {

    var spy = rope().stub({
       data: [
        {name: 'Al'},
        {name: 'Sue'},
        {name: 'Xerxes'}] 
    var foo = moquire('foo', {minq: spy})

    foo().then(function (result) {
      result.should.deep.equal({name: 'Xerxes'})
    }).then(done, done)



rope() => MinqFakeBuilder

Constructor function. Returns a new MinqTestBuilder object.

MinqFakeBuilder#stub(config) => MinqFakeBuilder

Chainable. Set up return values for queries. config is an object with these properties:

  • data: (required) The return value. Depending on the expected cardinality of the query (eg, minq#one vs minq#toArray), this should be an Array or a scalar Object.
  • collection: The expected collection of the query.
  • where: The expected conditional clause of the query.

MinqFakeBuilder#minq() => MinqFake

Returns an object with the same interface as minq. Use this object in place of requiring minq in your functions under test.

Stub dispatch

When a single test is expecting multiple queries, you can distinguish return values by collection. For example, to test this:

function foo(userId) {
  return minq.from('users')
  .select({country: 1})
  .then(function (user) {
    return minq.from('countries')

you could do:

minq = rope()
  .stub({collection: 'users', data: {country: 12}})
  .stub({collection: 'countries', data: {name: 'Uganda'}})

foo('user2').then(function (val) {
  val.should.deep.equal({name: 'Uganda'})

  minq.queries[0].query.should.deep.equal({_id: 'user2'})
  minq.queries[1].query.should.deep.equal({_id: 'user2'})

Note that real minq#byId and minq#byIds coerce the values to BSON ObjectIds

This is likely to be refined in future versions.

Bonus knowledge

Minks are of the family Mustelidae, which also includes the weasels, otters and ferrets.

You may also be interested in how to put a harness on a tame mink


MIT. (c) 2013 jden See