Testing

Testing is more important than shipping. If you have no tests or an
inadequate amount, then every time you ship code you won’t be sure that you
didn’t break anything. Deciding on what constitutes an adequate amount is up
to your team, but having 100% coverage (all statements and branches) is how
you achieve very high confidence and developer peace of mind. This means that
in addition to having a great testing framework, you also need to use a
good coverage tool.

There’s no excuse to not write tests. There are plenty of good JS test frameworks, so find one that your team prefers.
When you find one that works for your team, then aim to always write tests
for every new feature/module you introduce. If your preferred method is
Test Driven Development (TDD), that is great, but the main point is to just
make sure you are reaching your coverage goals before launching any feature,
or refactoring an existing one.

Single concept per test

Bad:

  1. import assert from 'assert';
  2. describe('MakeMomentJSGreatAgain', () => {
  3. it('handles date boundaries', () => {
  4. let date;
  5. date = new MakeMomentJSGreatAgain('1/1/2015');
  6. date.addDays(30);
  7. assert.equal('1/31/2015', date);
  8. date = new MakeMomentJSGreatAgain('2/1/2016');
  9. date.addDays(28);
  10. assert.equal('02/29/2016', date);
  11. date = new MakeMomentJSGreatAgain('2/1/2015');
  12. date.addDays(28);
  13. assert.equal('03/01/2015', date);
  14. });
  15. });

Good:

  1. import assert from 'assert';
  2. describe('MakeMomentJSGreatAgain', () => {
  3. it('handles 30-day months', () => {
  4. const date = new MakeMomentJSGreatAgain('1/1/2015');
  5. date.addDays(30);
  6. assert.equal('1/31/2015', date);
  7. });
  8. it('handles leap year', () => {
  9. const date = new MakeMomentJSGreatAgain('2/1/2016');
  10. date.addDays(28);
  11. assert.equal('02/29/2016', date);
  12. });
  13. it('handles non-leap year', () => {
  14. const date = new MakeMomentJSGreatAgain('2/1/2015');
  15. date.addDays(28);
  16. assert.equal('03/01/2015', date);
  17. });
  18. });