National Park of Minnesota

npm

Need private packages and team management tools?Check out npm Orgs. »

test-mongoose-utils

0.4.1 • Public • Published

Test Mongoose Utils

Installation

$ npm install test-mongoose-utils

Example Usage

const TestMongooseUtils = require('test-mongoose-utils');
const tmu = new TestMongooseUtils();
 
const Todo = require('./Todo');
 
describe('module', () => {
  before(done => {
    tmu.registerModels([Todo]); // Enables some functionality.
    // connect to mongoose...
  });
 
  after(done => {
    tmu.restore(); // Restores spies.
    // disconnect to mongoose...
  });
 
  afterEach(() => {
    tmu.reset(); // Resets spies' records.
  });
 
  test('Todo uuid is unique', done => {
    const data = { uuid: 'bananaMan' };
    const createTodo = mainCb =>
      tmu.assertChanges({ // Will assert @expectedChanges after @act.
        act: cb =>
          Todo.create(data, cb),
        expectedChanges: {
          db: {
            // Tells tmu to assert that Todo.count({}) incr's by 1 after @act.
            counts: [[Todo, {}, 1]]
          }
        }
      }, mainCb);
    const createTodoDupe = mainCb =>
      tmu.assertChanges({ // Will assert @expectedChanges after @act.
        act: cb =>
          Todo.create(data, cb),
        expectedChanges: {
          db: {
            // Tells tmu to assert that Model.<mutate>
            // or Model.prototype.<mutate> methods were not called.
            wasMutated: [[Todo, false]]
          }
        }
      }, mainCb);
 
    async.series([
      createTodo,
      createTodoDupe
    ], done);
  });
});

install

npm i test-mongoose-utils

Downloadsweekly downloads

1

version

0.4.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability