简体   繁体   中英

mongodb client not connecting in jest test

I am trying to setup an integration test for apollo graphql and need to connect to my mongodb database but this doesnt seem to be working. See the below code:

const MongoClient = require('mongodb').MongoClient
const LOADER_URI = 'mongodb://localhost:27017'

describe('ApolloIntegrationTest', () => {
  test('Test', () => {
    MongoClient.connect(URI, (err, client) => {
      if(err) throw err
      const pulseCore = client.db('pulse-core')
      console.log(pulseCore)
      const books = pulseCore.collection('books')
      console.log(books)
      client.close()
    })
  })
});

When i run the test, i expected to see the console logs printing but nothing prints when the test finishes. Not sure what i am doing wrong here.

Are you using mongo with authentiation enabled? Then you may be missing username and password in LOADER_URI

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM