From 54688d44f6da1ded311e3710e648393627553ae0 Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Sun, 14 Nov 2021 08:24:15 +1000 Subject: [PATCH] test: add failing tests --- .../AnimationFrameScheduler-spec.ts | 23 ++++++++++++++++++- spec/schedulers/AsapScheduler-spec.ts | 23 ++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/spec/schedulers/AnimationFrameScheduler-spec.ts b/spec/schedulers/AnimationFrameScheduler-spec.ts index 0a80e0c882..df64eb53d0 100644 --- a/spec/schedulers/AnimationFrameScheduler-spec.ts +++ b/spec/schedulers/AnimationFrameScheduler-spec.ts @@ -212,6 +212,27 @@ describe('Scheduler.animationFrame', () => { }); }); - it.skip('should properly cancel an unnecessary flush', (done) => { + it('should properly cancel an unnecessary flush', (done) => { + const sandbox = sinon.createSandbox(); + const cancelAnimationFrameStub = sandbox.stub(animationFrameProvider, 'cancelAnimationFrame').callThrough(); + + let a: Subscription; + let b: Subscription; + let c: Subscription; + + a = animationFrameScheduler.schedule(() => { + expect(animationFrameScheduler.actions).to.have.length(1); + c = animationFrameScheduler.schedule(() => { /* stupid lint rule */ }); + expect(animationFrameScheduler.actions).to.have.length(2); + // What we're testing here is that the unsubscription of action c effects + // the cancellation of the animation frame in a scenario in which the + // actions queue is not empty - it contains action b. + c.unsubscribe(); + expect(animationFrameScheduler.actions).to.have.length(1); + expect(cancelAnimationFrameStub).to.have.callCount(1); + sandbox.restore(); + done(); + }); + b = animationFrameScheduler.schedule(() => { /* stupid lint rule */ }); }); }); diff --git a/spec/schedulers/AsapScheduler-spec.ts b/spec/schedulers/AsapScheduler-spec.ts index 846860747b..1ce8043394 100644 --- a/spec/schedulers/AsapScheduler-spec.ts +++ b/spec/schedulers/AsapScheduler-spec.ts @@ -262,6 +262,27 @@ describe('Scheduler.asap', () => { }); }); - it.skip('should properly cancel an unnecessary flush', (done) => { + it('should properly cancel an unnecessary flush', (done) => { + const sandbox = sinon.createSandbox(); + const clearImmediateStub = sandbox.stub(immediateProvider, 'clearImmediate').callThrough(); + + let a: Subscription; + let b: Subscription; + let c: Subscription; + + a = asapScheduler.schedule(() => { + expect(asapScheduler.actions).to.have.length(1); + c = asapScheduler.schedule(() => { /* stupid lint rule */ }); + expect(asapScheduler.actions).to.have.length(2); + // What we're testing here is that the unsubscription of action c effects + // the cancellation of the microtask in a scenario in which the actions + // queue is not empty - it contains action b. + c.unsubscribe(); + expect(asapScheduler.actions).to.have.length(1); + expect(clearImmediateStub).to.have.callCount(1); + sandbox.restore(); + done(); + }); + b = asapScheduler.schedule(() => { /* stupid lint rule */ }); }); });