mongo-test-suit
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

A set of helper utility functions that makes testing MongoDB-based projects quick, nimble and readable. Written in Typescript.

Installation

NPM Info

Build Status

Example usage

import { initializeTestDB, getCollectionSnapshot, flushDb, closeDb } from 'mongo-test-suit'
import * as randomString from 'randomstring'
import { ObjectId } from 'mongodb'

const dbName = `my-db-${randomString.generate(7)}`
const uri = `mongodb://localhost/${dbName}`

beforeAll(async () => {
  await initializeTestDB(uri)
})

afterAll(async () => {
  await flushDb()
  await closeDb()
})

describe('myNeatFunction()', () => {
  test('It does what you think it does', async () => {
    // Go about your business
    // Now get a snapshot of the collection
    expect(await getCollectionSnapshot({ collectionName: 'MyCollection' })).toMatchSnapshot()
  })
})

Full API documentation here

Author

Ehab Khaireldin

License

This project is licensed under the MIT License

Package Sidebar

Install

npm i mongo-test-suit

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

12.1 kB

Total Files

11

Last publish

Collaborators

  • ehab_khaireldin