Created
April 13, 2018 11:10
-
-
Save aphofstede/7cc26561a9616a470b166c3353bdbc03 to your computer and use it in GitHub Desktop.
debounce with fake timer test
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 'expect' | |
import sinon from 'sinon' | |
import _ from 'lodash' | |
describe.only ('Debounce', () => { | |
let clock | |
beforeEach(() => { | |
clock = sinon.useFakeTimers(); | |
}) | |
afterEach(() => { | |
clock.restore() | |
}) | |
it ('can stub clock for debounce', function () { | |
let spy = sinon.spy(); | |
_.debounce(spy, 1000)(); | |
expect(spy.callCount).toEqual(0); | |
clock.tick(1); | |
expect(spy.callCount).toEqual(0); | |
clock.tick(998); | |
expect(spy.callCount).toEqual(0); | |
clock.tick(1); | |
expect(spy.callCount).toEqual(1); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment