Git Product home page Git Product logo

Comments (4)

danielbayerlein avatar danielbayerlein commented on July 29, 2024

Does anyone have an example implementation?

from jest-mongodb.

vladholubiev avatar vladholubiev commented on July 29, 2024

I've never used mongoose so I can only hope for others to fill this gap. Contributions are welcome

from jest-mongodb.

leosuncin avatar leosuncin commented on July 29, 2024

It almost the same as in the README, I used here https://github.com/leosuncin/fakeshop-api

import mongoose from 'mongoose'

const schema = new Schema({
  name: String
})
const Model = mongoose.model('Test', schema)

beforeAll(async () => {
  await mongoose.connect(process.env.MONGO_URL)
})

afterAll(async () => {
  await mongoose.disconnect()
})

test('create a new document', async () => {
  const document = new Model({ name: 'test 1' })
  await document.save()
  // The rest of the test
})

Edit: Don't forget to disconnect, if not Jest will hang up indefinitely

from jest-mongodb.

OneCricketeer avatar OneCricketeer commented on July 29, 2024

This is documented already in the memory server README

https://github.com/nodkz/mongodb-memory-server#simple-test-with-mongoclient-in-jest

from jest-mongodb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.