From 692fc143b08eafce596eb79a6ecea2beef99738d Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Wed, 10 Apr 2024 08:58:11 +0200 Subject: [PATCH 1/4] 32129139: Remove conditional expression in test --- src/test/htmlCanvasTest.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/test/htmlCanvasTest.js b/src/test/htmlCanvasTest.js index e2014201..528510e0 100644 --- a/src/test/htmlCanvasTest.js +++ b/src/test/htmlCanvasTest.js @@ -219,15 +219,10 @@ describe("htmlCanvas", () => { it("can omit nested tags", () => { withCanvas((html) => { // Arrange: a inner and outer div with a span as inner child - // where the child is omited based on a flag - let hasSomeText = false; - + // where the child is omitted html.div( { id: "outer_div" }, - html.div( - { id: "inner_div" }, - hasSomeText ? html.span("Some text") : html.omit(), - ), + html.div({ id: "inner_div" }, html.omit()), ); // Assert: that outer div rendered From 2105617aa1429befd534d10cc7753060b8a50233 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Wed, 10 Apr 2024 08:58:53 +0200 Subject: [PATCH 2/4] 32129139: Add expected error message in assertions --- src/test/htmlCanvasTest.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/test/htmlCanvasTest.js b/src/test/htmlCanvasTest.js index 528510e0..aae36968 100644 --- a/src/test/htmlCanvasTest.js +++ b/src/test/htmlCanvasTest.js @@ -287,11 +287,15 @@ describe("htmlCanvas", () => { withCanvas((html) => { expect(() => { html.render(null); - }).toThrowError(); + }).toThrowError( + "Cannot read properties of null (reading 'appendToBrush')", + ); expect(() => { html.render(undefined); - }).toThrowError(); + }).toThrowError( + "Cannot read properties of undefined (reading 'appendToBrush')", + ); }); }); From a10083824c26f27150ad5ebd2814ca9500f89c9e Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Wed, 10 Apr 2024 09:09:02 +0200 Subject: [PATCH 3/4] 32129139: Split 1 large assertion into 2 smaller ones --- src/test/router/routerTest.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/router/routerTest.js b/src/test/router/routerTest.js index 6c847b66..4aab20f9 100644 --- a/src/test/router/routerTest.js +++ b/src/test/router/routerTest.js @@ -191,7 +191,9 @@ describe("router", () => { aRouter.addRoute({ pattern: "/user/#userid/order/#orderid", action: function (userid, orderid) { - expect(userid === "john" && orderid === "1").toBeTruthy(); + expect(userid).toEqual("john"); + expect(orderid).toEqual("1"); + this.unbind(); // clean-up done(); // execute asserts }, From 3e9198221363451891250d43b0d76fe05969b521 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Wed, 10 Apr 2024 09:14:09 +0200 Subject: [PATCH 4/4] 32129139: Use assertions more specific than toHaveBeenCalled() --- src/test/router/routerTest.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/router/routerTest.js b/src/test/router/routerTest.js index 4aab20f9..69db6721 100644 --- a/src/test/router/routerTest.js +++ b/src/test/router/routerTest.js @@ -133,7 +133,7 @@ describe("router", () => { aRouter.resolveUrl("/user/"); // Assert that callback was executed - expect(spy).toHaveBeenCalled(); + expect(spy).toHaveBeenCalledWith(jasmine.anything()); }); it("resolveUrl triggers routeMatched event", (done) => { @@ -183,7 +183,7 @@ describe("router", () => { aRouter.resolveUrl("/user/"); // Assert that callback was executed - expect(spy).toHaveBeenCalled(); + expect(spy).toHaveBeenCalledWith(jasmine.anything()); }); it("resolveUrl pass values to action", (done) => { @@ -354,7 +354,7 @@ describe("router", () => { aRouter.resolveUrl("APathNotInDefaultRouterButInPipedRouter"); // Assert that second router matched the route - expect(spy).toHaveBeenCalled(); + expect(spy).toHaveBeenCalledWith({}); anotherRouter.stop(); }); @@ -373,7 +373,7 @@ describe("router", () => { aRouter.resolveUrl("/a/b/c"); // Assert that second router matched the route - expect(spy).toHaveBeenCalled(); + expect(spy).toHaveBeenCalledTimes(1); anotherRouter.stop(); });