From d1992274cbe007b67ca93e9ae60291d23e6e610b Mon Sep 17 00:00:00 2001 From: Florent Date: Tue, 6 Jul 2021 14:52:58 +0200 Subject: [PATCH] Test enhancement (fix given / when / then) --- tests/index-spec.ts | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/tests/index-spec.ts b/tests/index-spec.ts index f63ba86..c2289e0 100644 --- a/tests/index-spec.ts +++ b/tests/index-spec.ts @@ -416,26 +416,32 @@ describe("test class RSS: jsonfile", function () { // when myListener.start(); + await clock.tickAsync(1); + // then - await clock.tickAsync(1); expect(updateListenerSpy).to.have.been.calledOnce; - expect(newEntriesListenerSpy).to.not.have.been.called; + expect(newEntriesListenerSpy).to.have.been.calledOnce; // given stubParser.resolves(newRSSOutput); - // then + // when await clock.tickAsync(60000); + + + // then expect(updateListenerSpy).to.have.been.calledTwice; - expect(newEntriesListenerSpy).to.have.been.calledOnce; + expect(newEntriesListenerSpy).to.have.been.calledTwice; expect(newEntriesListenerSpy).to.have.been.calledWith([newEntry]); // given newEntriesListenerSpy.resetHistory(); - // then + // when await clock.tickAsync(60000); + + // then expect(updateListenerSpy).to.have.been.calledThrice; expect(updateListenerSpy).to.have.been.calledWith(mockedRSSOutput); expect(newEntriesListenerSpy).to.not.have.been.called; @@ -482,17 +488,20 @@ describe("test class RSS: jsonfile", function () { // when myListener.start(); + await clock.tickAsync(1); + // then - await clock.tickAsync(1); expect(updateListenerSpy).to.have.been.calledOnce; expect(newEntriesListenerSpy).to.not.have.been.calledOnce; // given stubParser.resolves(newRSSOutput); - // then + // when await clock.tickAsync(60000); + + // then expect(updateListenerSpy).to.have.been.calledTwice; expect(newEntriesListenerSpy).to.have.been.calledOnce; expect(newEntriesListenerSpy).to.have.been.calledWith([newEntry]); @@ -500,8 +509,10 @@ describe("test class RSS: jsonfile", function () { // given newEntriesListenerSpy.resetHistory(); - // then + // when await clock.tickAsync(60000); + + // then expect(updateListenerSpy).to.have.been.calledThrice; expect(updateListenerSpy).to.have.been.calledWith(mockedRSSOutput); expect(newEntriesListenerSpy).to.not.have.been.called;