The Ultimate Guide to Unit Testing in JavaScript.

A Thread...

"A unit test should test the behavior of a unit of work."

Unit tests are isolated and independent of each other.

- Any given behavior should be specified in one and only one test

- The execution/order of execution of one test cannot affect the others

- Repeatable

- Fast
"Ultimate Guidelines Which Helped Me a Lot."

- Whenever possible, use TDD

- Structure your tests properly

- Name your tests properly

- Don't comment out tests

- Avoid logic in your tests

- Don't write unnecessary expectations

- Know your testing framework API
- Consider using factory functions in the tests

- Don't test multiple concerns in the same test

- Cover the general case and the edge cases

- Test the behavior, not the internal implementation

- Don't mock everything

- Create new tests for every defect

- Test simple actions
- Review test code first

- When applying TDD, always start by writing the simplest failing test

- When applying TDD, always make small steps in each test-first cycle

- Properly set up the actions that apply to all the tests involved

Remember "Unit tests are code too"
Ok, I'll stop here.

Note: These guidelines can be leveraged for all the languages capable of unit testing.

Check out more in the blog post. ⬇

The Ultimate Guide to Unit Testing in JavaScript.

🔗 https://t.co/wvqfoN8ZdD

You May Also Like

“We don’t negotiate salaries” is a negotiation tactic.

Always. No, your company is not an exception.

A tactic I don’t appreciate at all because of how unfairly it penalizes low-leverage, junior employees, and those loyal enough not to question it, but that’s negotiation for you after all. Weaponized information asymmetry.

Listen to Aditya


And by the way, you should never be worried that an offer would be withdrawn if you politely negotiate.

I have seen this happen *extremely* rarely, mostly to women, and anyway is a giant red flag. It suggests you probably didn’t want to work there.

You wish there was no negotiating so it would all be more fair? I feel you, but it’s not happening.

Instead, negotiate hard, use your privilege, and then go and share numbers with your underrepresented and underpaid colleagues. […]