测试

一些好的覆盖工具

一些好的 JS 测试框架

单一的测试每个概念

反例:

  1. const assert = require('assert');
  2. describe('MakeMomentJSGreatAgain', function() {
  3. it('handles date boundaries', function() {
  4. let date;
  5. date = new MakeMomentJSGreatAgain('1/1/2015');
  6. date.addDays(30);
  7. date.shouldEqual('1/31/2015');
  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. });

正例:

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