Ticket: Projection Test for 3 entries not passing

> server@1.0.0 test /home/msrivastava/Documents/MongoDB/M220/mflix-js
> jest --passWithNoTests "projection.test.js"

Determining test suites to run...Setup Mongo Connection
optional dependency [kerberos] found but version [0.0.24] did not satisfy constraint [^1.0.0]
 FAIL  test/projection.test.js (14.848s)
  Projection
✓ Can perform a country search for one country (311ms)
✕ Can perform a country search for three countries (10030ms)

  ● Projection › Can perform a country search for three countries

Timeout - Async callback was not invoked within the 10000ms timeout specified by jest.setTimeout.

  17 |   })
  18 | 
> 19 |   test("Can perform a country search for three countries", async () => {
     |   ^
  20 |     const countriesList = ["Russia", "Japan", "Mexico"]
  21 |     const movies = await MoviesDAO.getMoviesByCountry(countriesList)
  22 |     expect(movies.length).toEqual(2788)

  at Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:85:20)
  at test (test/projection.test.js:19:3)
  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 next] (node_modules/regenerator-runtime/runtime.js:114:21)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        15.026s
Ran all test suites matching /projection.test.js/i.
Teardown Mongo Connection
Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
(node:10351) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'addExpectationResult' of undefined
(node:10351) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:10351) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
npm ERR! Test failed.  See above for more details.

Even tried increasing the timeout to 10000. Still doesn’t work. Although on increasing this time period to 50000, it returns the error that all the fields are returned.

My query is correct as well because I tested it in Mongo Shell, and it returns all the expected outputs but its not working here.

Please help.

static async getMoviesByCountry(countries) {
    let cursor
    try {
      cursor = await movies.find({countries: {$in: countries}},{title:1})
    } catch (e) {
      console.error(`Unable to issue find command, ${e}`)
      return []
    }
    return cursor.toArray()
  }
1 Like

github mongodb node driver for driver version 3

%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA%20%D1%8D%D0%BA%D1%80%D0%B0%D0%BD%D0%B0%20%D0%BE%D1%82%202019-02-14%2021-18-50

12 Likes

You solved my problem.

Yes it solved my problem. Thank You imareo!

Why would the test for 1 document pass using the old syntax though?
coll.find({ a: 42 }, { someField: 1 });

Seems to work for one document, not for many?

I too am getting this error

What is the solution to this problem please?

Putting the keyword projection in the query passed my test too… thx!!