Skip to content

Commit 37785fb

Browse files
ergunshDevtools-frontend LUCI CQ
authored andcommitted
[Gardener] Use sinon.useFakeTimers instead of stubbing setTimeout
The issue is: * We stub out `setTimeout`, it turns from `trackingSetTimeout` to `stubbedTestTimeout`. * The test restores it, so it turns to `trackingSetTimeout`. * On `restoreAll`, `window['setTimeout']` returns to `originalSetTimeout`. * Calling `sinon.restore()` makes `window['setTimeout']` return to `trackingSetTimeout`. Then, when we stub out `setTimeout` in `startTrackingAsyncActivity`, the original is returned as `trackingSetTimeout` whereas it should have returned as `originalSetTimeout`. Bug: none Change-Id: I4c0e376368507b16e57b803eff7b5a04d4e9f7f0 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6926730 Auto-Submit: Ergün Erdoğmuş <[email protected]> Commit-Queue: Ergün Erdoğmuş <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]> Reviewed-by: Nikolay Vitkov <[email protected]>
1 parent f2cfd21 commit 37785fb

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

front_end/ui/legacy/UIUtils.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,20 @@ describe('UIUtils', () => {
136136

137137
describe('LongClickController', () => {
138138
it('does not invoke callback when disposed', () => {
139+
const clock = sinon.useFakeTimers({toFake: ['setTimeout']});
139140
const el = document.createElement('div');
140141
const callback = sinon.spy();
141142
const controller = new UI.UIUtils.LongClickController(el, callback);
142-
// @ts-expect-error
143-
const setTimeout = sinon.stub(window, 'setTimeout').callsFake(cb => cb());
144143

145144
el.dispatchEvent(new PointerEvent('pointerdown'));
145+
clock.runAll();
146146
sinon.assert.calledOnce(callback);
147147

148148
controller.dispose();
149149

150150
el.dispatchEvent(new PointerEvent('pointerdown'));
151151
sinon.assert.calledOnce(callback);
152-
153-
setTimeout.restore();
152+
clock.restore();
154153
});
155154
});
156155

0 commit comments

Comments
 (0)