0.0.2 • Published 3 years ago

mongo-test-suit v0.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

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