🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///

Untitled Lesson

Total XP: 0|💻 backend XP: 0

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

Select an unlocked node to view details root

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Common Pitfalls & Errors

The Error //

Forgetting to return or await a Promise inside a Mocha `it()` block, causing the test to pass falsely

// Wrong: test passes even if getUser() rejects or the assertion fails later it('fetches a user', () => { getUser(1).then(user => expect(user.name).to.equal('Bob')); }); // Correct: Mocha waits for the returned/awaited promise it('fetches a user', async () => { const user = await getUser(1); expect(user.name).to.equal('Bob'); });

The Solution //

If an async assertion is not awaited (or the returned Promise isn't handed back to Mocha), the test function resolves immediately while the assertion is still pending, and Mocha marks it as passed before the real check ever runs. Always `await` async calls inside `it()`, or return the Promise chain directly.

The Error //

Mixing Chai's `expect` chainable words with Jest matcher syntax after migrating a suite

// Wrong: Chai syntax run under Jest expect(result).to.equal(5); // TypeError: expect(...).to is undefined // Correct: Jest's own matcher syntax expect(result).toBe(5);

The Solution //

Chai uses English-like chains like `expect(x).to.equal(5)` while Jest matchers are direct calls like `expect(x).toBe(5)` — copy-pasting tests between the two frameworks without converting the assertion syntax produces a 'is not a function' error at runtime because Jest's expect() doesn't have a `.to` property, and vice versa.

Continue Learning