Last active
November 13, 2019 15:46
-
-
Save togakangaroo/e7934b00571c397f1c96c009a82cf5e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { expect } from 'chai' | |
import { useFakeTimers } from 'sinon' | |
const createStopWatch = () => { | |
const createDisplays = (main, laps = []) => ({main, laps}) | |
let startTime | |
const sw = { | |
displays: createDisplays(null), | |
toggle: () => { | |
sw.displays = createDisplays(0) | |
startTime = new Date() | |
setInterval(() => { | |
sw.displays.main = new Date() - startTime | |
}, 10) | |
}, | |
} | |
return sw | |
} | |
// ... | |
const elapses = (ms, inner) => { | |
describe(`${toSec(ms)} elapses`, () => { | |
beforeEach(() => clock.tick(ms)) | |
inner() | |
}) | |
} | |
main_and_laps_should_display(null, []) | |
elapses(1000, () => { | |
main_and_laps_should_display(null, []) | |
}) | |
describe(`started`, () => { | |
beforeEach(() => sw.toggle()) | |
main_and_laps_should_display(0, []) | |
elapses(10000, () => { | |
main_and_laps_should_display(10000, []) | |
elapses(1000, () => { | |
main_and_laps_should_display(11000, []) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment