Skip to content

Instantly share code, notes, and snippets.

@togakangaroo
Last active November 13, 2019 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save togakangaroo/e7934b00571c397f1c96c009a82cf5e7 to your computer and use it in GitHub Desktop.
Save togakangaroo/e7934b00571c397f1c96c009a82cf5e7 to your computer and use it in GitHub Desktop.
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