Skip to content

Commit

Permalink
Merge pull request #487 from foretagsplatsen/32129139/Improve_some_un…
Browse files Browse the repository at this point in the history
…it_tests

32129139: Improve some unit tests
  • Loading branch information
DamienCassou authored Apr 10, 2024
2 parents 4fde543 + 3e91982 commit b45a487
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
17 changes: 8 additions & 9 deletions src/test/htmlCanvasTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -292,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')",
);
});
});

Expand Down
12 changes: 7 additions & 5 deletions src/test/router/routerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -183,15 +183,17 @@ 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) => {
// Arrange a route that have two mandatory parameters
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
},
Expand Down Expand Up @@ -352,7 +354,7 @@ describe("router", () => {
aRouter.resolveUrl("APathNotInDefaultRouterButInPipedRouter");

// Assert that second router matched the route
expect(spy).toHaveBeenCalled();
expect(spy).toHaveBeenCalledWith({});
anotherRouter.stop();
});

Expand All @@ -371,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();
});

Expand Down

0 comments on commit b45a487

Please sign in to comment.