Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5e9319

Browse files
author
Andrew Mead
committed
Lesson: Writing Your Own Tests
1 parent efbfbf9 commit b5e9319

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

task-manager/src/math.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
const calculateTip = (total, tipPercent = .25) => total + (total * tipPercent)
22

3+
const fahrenheitToCelsius = (temp) => {
4+
return (temp - 32) / 1.8
5+
}
6+
7+
const celsiusToFahrenheit = (temp) => {
8+
return (temp * 1.8) + 32
9+
}
10+
311
module.exports = {
4-
calculateTip
12+
calculateTip,
13+
fahrenheitToCelsius,
14+
celsiusToFahrenheit
515
}

task-manager/tests/math.test.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { calculateTip } = require('../src/math')
1+
const { calculateTip, celsiusToFahrenheit, fahrenheitToCelsius } = require('../src/math')
22

33
test('Should calculate total with tip', () => {
44
const total = calculateTip(10, .3)
@@ -10,13 +10,12 @@ test('Should calculate total with default tip', () => {
1010
expect(total).toBe(12.5)
1111
})
1212

13-
//
14-
// Why test?
15-
//
16-
// - Saves time
17-
// - Creates reliable software
18-
// - Gives flexibility to developers
19-
// - Refactoring
20-
// - Collaborating
21-
// - Profiling
22-
// - Peace of mind
13+
test('Should convert 32 F to 0 C', () => {
14+
const temp = fahrenheitToCelsius(32)
15+
expect(temp).toBe(0)
16+
})
17+
18+
test('Should convert 0 C to 32 F', () => {
19+
const temp = celsiusToFahrenheit(0)
20+
expect(temp).toBe(32)
21+
})

0 commit comments

Comments
 (0)