-
Notifications
You must be signed in to change notification settings - Fork 142
/
car-test.js
35 lines (26 loc) · 1.01 KB
/
car-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
let subject, gasPedal, accelerometer, Brake
module.exports = {
beforeEach: function () {
gasPedal = td.replace('../../lib/gas-pedal') // <-- a plain ol' function
accelerometer = td.replace('../../lib/accelerometer') // <-- an obj of functions
Brake = td.replace('../../lib/brake') // <-- a constructor function
td.replace('../../lib/copilot', function () { return 'HIGHFIVE' }) // <-- a manual override
subject = require('../../lib/car')
},
'.goSixty': {
'not yet going 60 -> pushes the pedal down 5 units': function () {
td.when(accelerometer.read()).thenReturn(55)
subject.goSixty()
td.verify(gasPedal(5))
},
'going over 60 -> engages the brake for 2 units': function () {
td.when(accelerometer.read()).thenReturn(62)
subject.goSixty()
td.verify(Brake.prototype.engage(2))
},
'going exactly 60 invokes the copilot for some weird reason': function () {
const result = subject.goSixty()
assert.equal(result, 'HIGHFIVE')
}
}
}