Issue tracker - get all issues for a project fails

The following test fails

You can send a GET request to /api/issues/{projectname} for an array of all issues for that specific projectname, with all the fields present for each issue.

the console error:

Error: expected [ Array(5) ] to have a length of 3 but got 5

I believe that the error is that the test expects the response to be an array of length 3 (the 3 issues the test posts) but the response has the data of previous post tests (2 issues) and any data added before to the database.

Replit link
https://Issue-Tracker.esraaabdou.repl.co

Challenge: Issue Tracker

Link to the challenge:

You may just want to clear out your database before testing. Assuming you are using mongo you can just goto atlas and click on your collections and delete any relevant collections. Another method would be simply to check if the data already exists in your database and if it does simply do not add it your database.

Just to expand on this a bit, many projects will use a testing database that is separate from the real database. You can even set up your environment to use the testing db when you are in test mode or the real one when your code is running in deployment. If you use a testing db, then you can use the before and after hooks in your test runner (mocha presumably) to purge the entire db (no need to login to your db provider!) to start fresh or to add some records for future tests. It’s nice to start with a db in a known state before you start running tests.

If emptying the db doesn’t fix your problem, you should post a link to your live project on repl.it (or wherever) so that you can get some better help.

1 Like

I clear the database before testing, the tests before the failing test add 2 documents to the collection.
after running the tests I find 5 document in the collection.

I guess emptying the db isn’t helping.
I added the replit link

Well, the GET tests are definitely picking up too many entries but I can’t tell where the problem is. Further, the GET tests find more issues on every run (the old ones keep getting found). You’ll have to post the link to your code too so we can (possibly) find the problem.

I added a link to my code

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.