Skip to content

Commit f871283

Browse files
committed
Single concept per test
1 parent 8f4a8d2 commit f871283

File tree

1 file changed

+60
-9
lines changed

1 file changed

+60
-9
lines changed

README.md

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# clean-code-javascript
22

33
## Table of Contents
4-
0. [Introduction](#introduction)
5-
1. [Variables](#variables)
6-
2. [Functions](#functions)
7-
3. [Objects and Data Structures](#objects-and-data-structures)
8-
4. [Classes](#classes)
9-
5. [Testing](#testing)
10-
6. [Concurrency](#concurrency)
11-
7. [Formatting](#formatting)
12-
8. [Comments](#comments)
4+
1. [Introduction](#introduction)
5+
2. [Variables](#variables)
6+
3. [Functions](#functions)
7+
4. [Objects and Data Structures](#objects-and-data-structures)
8+
5. [Classes](#classes)
9+
6. [Testing](#testing)
10+
7. [Concurrency](#concurrency)
11+
8. [Formatting](#formatting)
12+
9. [Comments](#comments)
1313

1414
## Introduction
1515
![Humorous image of software quality estimation as a count of how many expletives
@@ -1555,6 +1555,57 @@ Test Driven Development (TDD), that is great, but the main point is to just
15551555
make sure you are reaching your coverage goals before launching any feature,
15561556
or refactoring an existing one.
15571557

1558+
### Single concept per test
1559+
1560+
**Bad:**
1561+
```javascript
1562+
const assert = require('assert');
1563+
1564+
describe('MakeMomentJSGreatAgain', function() {
1565+
it('handles date boundaries', function() {
1566+
let date;
1567+
1568+
date = new MakeMomentJSGreatAgain('1/1/2015');
1569+
date.addDays(30);
1570+
date.shouldEqual('1/31/2015');
1571+
1572+
date = new MakeMomentJSGreatAgain('2/1/2016');
1573+
date.addDays(28);
1574+
assert.equal('02/29/2016', date);
1575+
1576+
date = new MakeMomentJSGreatAgain('2/1/2015');
1577+
date.addDays(28);
1578+
assert.equal('03/01/2015', date);
1579+
});
1580+
});
1581+
```
1582+
1583+
**Good**:
1584+
```javascript
1585+
const assert = require('assert');
1586+
1587+
describe('MakeMomentJSGreatAgain', function() {
1588+
it('handles 30-day months', function() {
1589+
let date = new MakeMomentJSGreatAgain('1/1/2015');
1590+
date.addDays(30);
1591+
date.shouldEqual('1/31/2015');
1592+
});
1593+
1594+
it('handles leap year', function() {
1595+
let date = new MakeMomentJSGreatAgain('2/1/2016');
1596+
date.addDays(28);
1597+
assert.equal('02/29/2016', date);
1598+
});
1599+
1600+
it('handles non-leap year', function() {
1601+
let date = new MakeMomentJSGreatAgain('2/1/2015');
1602+
date.addDays(28);
1603+
assert.equal('03/01/2015', date);
1604+
});
1605+
});
1606+
```
1607+
**[⬆ back to top](#table-of-contents)**
1608+
15581609
## **Concurrency**
15591610
### Use Promises, not callbacks
15601611
Callbacks aren't clean, and they cause excessive amounts of nesting. With ES6,

0 commit comments

Comments
 (0)