TICKET Connection - npm test -t db-connection failure

npm test -t db-connection failure.

what should the value for your-atlas-cluster-address on the .env file?

server@1.0.0 test W:\mongoDB\COURSES\190108\0108HANDOUTS\mflix-js
jest --passWithNoTests “db-connection”

Determining test suites to run…Setup Mongo Connection
FAIL I:/USERS/SPEXP/files/mongoDB/COURSES/190108/0108HANDOUTS/mflix-js/test/db-connection.test.js
● Test suite failed to run

TypeError: Cannot read property 'close' of undefined

  17 |
  18 |   async teardown() {
> 19 |     await this.global.mflixClient.close()
     |                                   ^
  20 |     await super.teardown()
  21 |   }
  22 |

  at MongoEnvironment.teardown (test/config/mongoEnvironment.js:19:35)
      at Generator.throw (<anonymous>)

Test Suites: 1 failed, 1 total

Same issue when i tried to run the ‘npm test -t mongoclient’ command
Determining test suites to run…Setup Mongo Connection
FAIL test/lessons/mongoclient.spec.js
● Test suite failed to run

TypeError: Cannot read property 'close' of undefined

  17 |
  18 |   async teardown() {
> 19 |     await this.global.mflixClient.close()
     |                                   ^
  20 |     await super.teardown()
  21 |   }
  22 |

  at MongoEnvironment.teardown (test/config/mongoEnvironment.js:19:35)
      at Generator.throw (<anonymous>)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.583s
Ran all test suites matching /mongoclient/i.
Teardown Mongo Connection
npm ERR! Test failed. See above for more details.

I need help too

I found the solution
Once you change the SECRET_KEY and MFLIX_DB_URI in dotenv_win file then navigate to that folder from command prompt and run the ren dotenv_win .env which it remove the dotenv_win name and reset to .env

env

Thanks Vimal,

I re-read the full instructions set word by word and able to figure it out…

my problem was that I had taken another course where I had used the ATLAS account and I thought it was the same, it wasn’t so after I re-read the instructions and stopped my ego from getting in front of my nose, I then was able to reason it out.

One thing I did find troublesome was the where the examples were confusing, but again after re-reading the instructions and several hours of testing I was able to figure it out. another thing I find surprising is how much this course is sooo different from the old 121 JavaScript course with so much hidden under the covers, but the fact that the DB is being manipulated in such a clear manner makes me very happy.

I finished all of the labs by Sunday night and felt very good. I’m linking this course really well so far.

Thanks for your help.

Luis-Carlos Rodriguez

Vimail,

the one test I could not get going was the connection-pooling, but I’ll work on that some other time.

regards,

Luis-Carlos

Havin simillar issue:
$ npm test -t mongoclient

server@1.0.0 test /Users/pavitenterprises/Documents/M220JS/mflix-js 2
jest --passWithNoTests “mongoclient”

Determining test suites to run…Setup Mongo Connection
FAIL test/lessons/mongoclient.spec.js (7.637s)
MongoClient
✓ Client initialized with URI (1899ms)
✕ Client initialized with URI and options (572ms)
✓ Database handle created from MongoClient (2055ms)
✕ Collection handle created from database handle (689ms)

● MongoClient › Client initialized with URI and options

TypeError: Cannot read property 'close' of undefined

  65 |                      expect(e).toBeNull();
  66 |              } finally {
> 67 |                      testClient.close();
     |                                 ^
  68 |              }
  69 |      });
  70 | 

  at close (test/lessons/mongoclient.spec.js:67:15)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:296:22)
  at Generator.prototype.(anonymous function) [as throw] (node_modules/regenerator-runtime/runtime.js:114:21)
  at step (node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
  at node_modules/babel-runtime/helpers/asyncToGenerator.js:30:13

● MongoClient › Collection handle created from database handle

TypeError: Cannot read property 'close' of undefined

  128 |                     expect(e).toBeNull();
  129 |             } finally {
> 130 |                     testClient.close();
      |                                ^
  131 |             }
  132 |     });
  133 | });

  at close (test/lessons/mongoclient.spec.js:130:15)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:296:22)
  at Generator.prototype.(anonymous function) [as throw] (node_modules/regenerator-runtime/runtime.js:114:21)
  at step (node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
  at node_modules/babel-runtime/helpers/asyncToGenerator.js:30:13

Test Suites: 1 failed, 1 total
Tests: 2 failed, 2 passed, 4 total
Snapshots: 0 total
Time: 7.815s, estimated 8s
Ran all test suites matching /mongoclient/i.
Teardown Mongo Connection
npm ERR! Test failed. See above for more details.