Test are not getting called when command is given [Solved]

My test are not running. I don’t know reason why it was happened.

Below is the error i am getting.

FAIL test/create-update-comments.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 |

If you are still stuck, try deleting node_modules folder and run “npm install” again.

okay, thanks for the advice :+1:

removing node_modules folder doesn’t seems to be working

Hi @Kajal_45824

Did you also run the “npm install” command after removing the node_modules folder ?
Can you also verify your MFLIX_DB_URI in your .env file is pointing to your Atlas Cluster with the correct username and password ?

Kindest regards,
Eoin

yes , i had run “npm install” after removing node_modules folder and has also verify the database uri but still not working

Hi @Kajal_45824

Can you verify your Atlas Cluster is running ?
Can you also share the full output from your console to help understand the exact error that you are encountering ?

Kindest regards,
Eoin

yes , cluster is running all well,
And this is what my error looks

npm test -t create-update-comments

server@1.0.0 test G:\React\mflix-js
jest --passWithNoTests “create-update-comments”

Determining test suites to run…Setup Mongo Connection

FAIL test/create-update-comments.test.js

● Test suite failed to run

TypeError: Cannot read property 'close' of undefined

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

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

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

I’m also getting same error - it was working fine yesterday. At the bottom I also have:

console.error src/dao/moviesDAO.js:17
Unable to establish a collection handle in moviesDAO: TypeError: Cannot read property ‘db’ of undefined

1 Like

I solved it on my end. I think the problem was coming from the example in the link for the connection-pooling ticket.

The link shows

// Connection URL
var url = 'mongodb://localhost:50000,localhost:50001/myproject';
// Use connect method to connect to the Server passing in
// additional options
MongoClient.connect(url, {
  poolSize: 10, ssl: true
}, function(err, db) {
  assert.equal(null, err);
  console.log("Connected correctly to server");

  db.close();
});

I removed the callback function and tests are running ok

1 Like