Cryptic failure messages, how to troubleshoot?

This new class format is extremely frustrating. We’re provided with a mountain of javascript and no idea how to initialize the driver or play around with the code. Just a pass/fail secret code and no real understanding of the process.

For example, how would I begin to troubleshoot this failure?

C:\M220\mflix-js>npm test -t projection

> server@1.0.0 test C:\M220\mflix-js
> jest --passWithNoTests "projection"

Determining test suites to run...Setup Mongo Connection
 FAIL  C:/M220/mflix-js/test/projection.test.js
√ Can perform a country search for one country (107ms)
x Can perform a country search for three countries (1844ms)

  ? Projection > Can perform a country search for three countries


Expected value to equal:
  ["_id", "title"]
  ["_id", "countries", "directors", "fullplot", "genres", "imdb", "lastupdated", "num_mflix_comments", "plot", "poster", "relea
sed", "runtime", "title", "tomatoes", "type", "writers", "year"]


- Expected
+ Received

  Array [
+   "countries",
+   "directors",
+   "fullplot",
+   "genres",
+   "imdb",
+   "lastupdated",
+   "num_mflix_comments",
+   "plot",
+   "poster",
+   "released",
+   "runtime",
+   "tomatoes",
+   "type",
+   "writers",
+   "year",

  19 |       const movieKeys = Object.keys(movie).sort()
  20 |       const expectedKeys = ["_id", "title"]
> 21 |       expect(movieKeys).toEqual(expectedKeys)
     |                         ^
  22 |     })
  23 |   })
  24 | })

  at toEqual (test/projection.test.js:21:25)
      at (<anonymous>)
  at map (test/projection.test.js:18:12)
  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)
  at step (node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
  at node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13

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


Here’s the command that I tried in the exercise:

  cursor = await movies.find({countries:{"$in":countries}},{project:{title:1}})

I’d prefer troubleshooting steps rather than being given a correct answer… Why did the first test pass and not the second one? How can I send the query without all the boilerplate so I can see what it’s returning? …etc.

Hi @Joe_96856,

Sorry that you are feeling frustrated, that is certainly not our intention.
The idea behind having tests that we can run and experiment with, is to allow you to have an iterative approach to the lab/ticket completion.

We’ll refine the test case messages to give a bit more of guidance of what is intended from each test case so it causes less friction.

Regarding this particular lab/ticket:

In the output of the test case you are getting this:

Expected value to equal: ["_id", "title"] 
Received: ["_id", "countries", "directors", "fullplot", "genres", "imdb", "lastupdated", "num_mflix_comments", "plot", "poster", "relea sed", "runtime", "title", "tomatoes", "type", "writers", "year"]

The test is checking all the field names of the returned document, by placing the into an array.
It is expecting

Expected value to equal: ["_id", "title"] 

but is getting from your code

Received: ["_id", "countries", "directors", "fullplot", "genres", "imdb", "lastupdated", "num_mflix_comments", "plot", "poster", "relea sed", "runtime", "title", "tomatoes", "type", "writers", "year"]

Can you see what you need to do ?

hint: Check your command spelling

Hi Norberto, I have done the same thing and looked up a few documentations as well. I am not sure what is going wrong. I tried with and without the project keyword, included quotes for the $in keyword as well. Not sure what is going wrong
P.S: I even tried to check the output by sending { title: 0 } just to make sure it fails but even then it gave the same output

The syntax here is invalid. I’d definitely look at

1 Like

Hi @Debanjan_81780 / @Joe_96856,

Go ahead and check the example available with the basic reads lesson test test/lessons/basic-reads.spec.js

There’s a clear example on how to build a projection.


Thanks a lot nathan and Norberto. I understood where I made the mistake

Thanks… I was able to get the correct encrypted code through trial and error. Your response helped me understand the error I was making.

I’m confused because I don’t know why the first test would pass, while the second one didn’t. I don’t know how to use the javascript driver to experiment with the feature, because it’s all tied into a mountan of code that was provided with no explanation. I’m sure with time these things will become clear, but right now I’m just going through the steps without really putting the concepts together.

Specifically, why did this test pass:
√ Can perform a country search for one country (107ms)

while this test failed:
x Can perform a country search for three countries (1844ms)

I would have expected both tests to pass or fail?

Thanks in advance…

1 Like