Node Course Jest Tests Too Outdated To Be Useful To Learn?

Hello, everyone.

I have been working through Mosh’s Node course. I have been using current libraries, instead of the versions he uses. So far, I have found plenty of little issues, but I have not found any major problems that I could not get past as a developer with some significant experience coding, debugging, and looking through docs.

However, I went through his sections on testing and added more Jest tests to get up to high test coverage. And I discovered major problems suppressed by the option “–detectOpenHandles,” which I had been after an error message recommended I use this to debug. When I removed the option to get ready to deploy, I got many errors, and the pattern of error changed each time I ran the tests together. The errors went away when I ran the tests each one on their own. NOT GOOD.

I was able to quickly get past errors about the address/port by using port = 0 for the test environment, so the ports could be assigned automatically. Many errors existed beyond this one. And they were, as I said, chaotic.

According to the docs, this option “implies —runInBand." That option means, the test run slowly, because they all run serially in the current process instead of creating a worker pool. So by default, instead of one at a time, they all run in a random pattern. This means that the cleanup code for database collections interferes with other setup code. Hence the chaotic failures.

Mosh does setup and teardown so that each test should have a clean database. That is not the way that Jest works. The performance loss of running tests on a single process is not recommended. I cannot fathom how folks are solving this issue in real development environments. They may be refactoring their setup and teardown. They may be using separate databases for each test suite.

The other parts of the course that were “outdated” were still highly useful in my opinion. But in this case, the lessons conflict with the way the actual software runs. There appears to be a design issue, a clash of principles. I will need to go and essentially “relearn” this, which I wish I had known before. I would not have spent nearly as much time on this part. I already had a lot of trust from doing prior courses with Mosh, so I was surprised and confused for a while. But I can see some folks on the forum had a much harder time with this experience, possibly because it was one of their first with his content.

I am wondering if this part of the course should be removed or updated. Or have at the very least a note added about this. Is this particular part still useful?

hi jmtucker, I pretty much agree on all of what you said. Had the same issues. Run ONE test file and no problem. Run TWO and I get one “port in use” error. Any two. Run all three and I get two “port in use” errors. I saw the --runInBand option but before that I came across a suggestion on here to use the --maxWorkers=1 option so my “scripts” look like this:

"scripts": {
    "test": "jest --watchAll --verbose --maxWorkers=1",
    "start": "node index.js"

This works fine with all three test files together.
No question that parts of the course are outdated and like you, I had issues and slogged through trial and error and googling for clues/answers. I put up three posts on all the issues and solutions. Im running Windows 10 and posted my package.json and using all the latest packages (as at early 2022).

I didnt enjoy the testing part of the course except Mosh’s technique for refactoring. I could see that in larger scale developments the testing can be critical but I wonder if big tech uses this. Code to test the code. And code to test the code that tests the code …?

Overall a great course. I have done a few of his courses including python, js and sql and started but got distracted with react. Maybe will get back to that shortly. Also doing courses with Angela Yu (NOW, you are talking OUT OF DATE) and Jonas Schmedtmann. Both very good. Jonas is meticulous (sometimes heavy going) but his support people are great, responsive and encouraging. Angela is good but no support and the only thing “2022” about her “Complete js Web Dev 2022” course is the title. It is SO outdated, I had to look for my Commodore 64! lol Both of them I came across on Udemy. Are you doing courses with others you could recommend? I definitely recommend Mosh despite the lack of support and some outdated stuff.

All of these courses SHOULD have an ADDENDUM file or something to post solutions / updates because you can waste many hours/days trying to find a solution when something doesnt work. Thankfully more people like yourself are posting and as a community we can help each other out. All the best!

IDC about tests

i skipped the section


Hi, kavfam!

I also like Brad Travery’s content. He has some things on YouTube and on Udemy. He tends to come back and do updated versions fairly often. I will take a look at these others!

I do think very highly of Mosh’s content. His design patterns lessons are exceptional in my opinion. I went through his React course quickly, but I had substantial prior experience and was using it as a refresher. He added a section about functional React. As someone who has worked as a React developer, I think it is of use to learn the class components. But folks should be prepared to spend some days on function components, either refactoring or remaking some things. On the surface, those changes are superficial. But in truth, some of the abstractions and design patterns are indeed different. A class component lifecycle hook does not translate directly to a function component hook. Both are lovely patterns, very well designed. But it can be frustrating and demoralizing to get those to “click,” same as any other abstraction created by someone else. And if you’re new to React, there can be a lot of folks online saying the changes are as simple as refactoring a few lines. Then you miss the real change and can hit walls later. I feel like it would be having your brain pulled in two different directions, potentially. Which is not great while learning early on.

I do wish there was a YouTube channel of folks going through the fixes / updates. More of Mosh’s course is still relevant than not, but there are serious drifts. The forum does help. Even just a running sheet of what’s deprecated going into a project would be helpful. But I understand why it’s difficult to keep up both for Mosh and those of us running through courses!

I am about to try to replace Fawn. It hasn’t been updated in four years and has critical security vulnerabilities. That’s JavaScript kryptonite. Lol.

Thanks for the info. I will check out Brad. Actually I saw someone else recommended the same and did a search on Udemy and hit Brad Schiff and his React course, so just started on that and so far its great and he is supporting his course - last post 7 days ago. He also puts up changes for latest packages. Will get back to Mosh’s React course next probably.
On Fawn I recently read an “exchange” between what I thought was a Fawn developer and a Fawn user where the dev told the user he was “entitled” expecting that a change to Fawn needs to be backward compatible. Not impressive. Good luck with the replacement. It seemed to me that since it is essentially comparing schemas it probably wouldnt be too hard to write a function to do that (says the optimist).