mongo-test-suit

A set of helper tools to test mongo-based projects

Usage no npm install needed!

<script type="module">
  import mongoTestSuit from 'https://cdn.skypack.dev/mongo-test-suit';
</script>

README

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