Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

32129139: Improve some unit tests #487

Merged
merged 4 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading