Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.