# mockable-mongo

> An in memory mongodb for tests and mocking

Latest version **0.0.4** (published 2020-10-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install mockable-mongo
pnpm add mockable-mongo
yarn add mockable-mongo
bun add mockable-mongo
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2020-10-04 |
| First published | 2020-10-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jake Overall |
| Maintainers | joverall22 |
| Keywords | mongodb, mongoose, ava, jest, mocha, chai |

## Links

- npm: https://www.npmjs.com/package/mockable-mongo
- Repository: https://github.com/jakeoverall/mockable-mongo
- Homepage: https://github.com/jakeoverall/mockable-mongo#readme
- Issues: https://github.com/jakeoverall/mockable-mongo/issues
- npm.io page: https://npm.io/package/mockable-mongo

## Dependencies (1)

- [mongo-in-memory](https://npm.io/package/mongo-in-memory.md) 0.0.5

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [@temporal-architect/claude-plugin](https://npm.io/package/@temporal-architect/claude-plugin.md) — 335 weekly downloads

## Recent versions

- 0.0.4 (latest) — 2020-10-04
- 0.0.3 — 2020-10-04
- 0.0.2 — 2020-10-04
- 0.0.1 — 2020-10-04

## README

mockable-mongo
=========

A library for mocking a MongoDb Instance in memory. 

```s
npm i -D mockable-mongo
```


#### Testing Mocha
Starts up a mongodb instance in a promise based approach allowing the call to be awaited. User can specify the name of the database the full connection string will be returned

```javascript
import MockMongo from 'mockable-mongo'
import Mongoose from 'mongoose'

describe('Testing with Mocha', () => {
    
    describe('Mongoose Connection', () => {
        const MONGO_SERVER = new MockMongo()
        
        mongoose.set("useNewUrlParser", true);
        mongoose.set("useFindAndModify", false);
        mongoose.set("useCreateIndex", true);
        mongoose.set("useUnifiedTopology", true);

        before(async done => {
            const CONNECTION_STRING = await MONGO_SERVER.start('myDb')
            await mongoose.connect(CONNECTION_STRING)
            done()
        })
        
        after(async done => {
            await mongoose.disconnect()
            await MONGO_SERVER.stop()
            done()
        })
    })
})

```

#### Testing with Ava
With ava be sure to spin up and teardown the db in each file as all tests are run in isolated worker environments

```javascript
import ava from 'ava'
import MockMongo from 'mockable-mongo'
import Mongoose from 'mongoose'

const MONGO_SERVER = new MockMongo()

ava.before('Setup DB', async t => {
    mongoose.set("useNewUrlParser", true);
    mongoose.set("useFindAndModify", false);
    mongoose.set("useCreateIndex", true);
    mongoose.set("useUnifiedTopology", true);
    const CONNECTION_STRING = await MONGO_SERVER.start('myDb')
    await mongoose.connect(CONNECTION_STRING)
});

//#region SUT TESTS
//#endregion

ava.after("Teardown", async t => {
    await mongoose.disconnect()
    await MONGO_SERVER.stop()
})

```

---
_Source: https://npm.io/package/mockable-mongo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
