Skip to content

Commit

Permalink
Switch from Chai should to expect
Browse files Browse the repository at this point in the history
  • Loading branch information
scottohara committed Aug 18, 2023
1 parent de5bc92 commit 0046e11
Show file tree
Hide file tree
Showing 29 changed files with 1,246 additions and 1,244 deletions.
94 changes: 48 additions & 46 deletions spec/public/components/list_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ describe("List", (): void => {
});

describe("object constructor", (): void => {
it("should return a List instance", (): Chai.Assertion => list.should.be.an.instanceOf(List));
it("should set the container", (): Chai.Assertion => list["container"].should.equal(container));
it("should set the item template", (): Chai.Assertion => list["itemTemplate"].should.equal(itemTemplate));
it("should set the group by", (): Chai.Assertion => (list["groupBy"] as string).should.equal(groupBy));
it("should set the list items", (): Chai.Assertion => list.items.should.deep.equal(items));
it("should attach a view event handler", (): Chai.Assertion => list["viewEventHandler"].should.equal(eventHandler));
it("should attach an edit event handler", (): Chai.Assertion => (list["editEventHandler"] as SinonStub).should.equal(eventHandler));
it("should attach a delete event handler", (): Chai.Assertion => (list["deleteEventHandler"] as SinonStub).should.equal(eventHandler));
it("should set the action", (): Chai.Assertion => (list["action"] as ListAction).should.equal(action));
it("should return a List instance", (): Chai.Assertion => expect(list).to.be.an.instanceOf(List));
it("should set the container", (): Chai.Assertion => expect(list["container"]).to.equal(container));
it("should set the item template", (): Chai.Assertion => expect(list["itemTemplate"]).to.equal(itemTemplate));
it("should set the group by", (): Chai.Assertion => expect(list["groupBy"] as string).to.equal(groupBy));
it("should set the list items", (): Chai.Assertion => expect(list.items).to.deep.equal(items));
it("should attach a view event handler", (): Chai.Assertion => expect(list["viewEventHandler"]).to.equal(eventHandler));
it("should attach an edit event handler", (): Chai.Assertion => expect(list["editEventHandler"] as SinonStub).to.equal(eventHandler));
it("should attach a delete event handler", (): Chai.Assertion => expect(list["deleteEventHandler"] as SinonStub).to.equal(eventHandler));
it("should set the action", (): Chai.Assertion => expect(list["action"] as ListAction).to.equal(action));
});

describe("refresh", (): void => {
Expand All @@ -86,14 +86,14 @@ describe("List", (): void => {
list.refresh();
});

it("should render the list", (): Chai.Assertion => containerElement.innerHTML.should.equal(renderHtml));
it("should render the list", (): Chai.Assertion => expect(containerElement.innerHTML).to.equal(renderHtml));

it("should attach a click handler to each item", (): void => {
document.querySelectorAll(`#${container} li:not([id])`).forEach((element: HTMLLIElement, index: number): void => {
element.dispatchEvent(new MouseEvent("click"));
tap.should.have.been.calledWith(index);
expect(tap).to.have.been.calledWith(index);
});
tap.callCount.should.equal(3);
expect(tap.callCount).to.equal(3);
});
});

Expand All @@ -104,14 +104,14 @@ describe("List", (): void => {
list.refresh();
});

it("should render the list", (): Chai.Assertion => containerElement.innerHTML.should.equal(renderHtml));
it("should render the list", (): Chai.Assertion => expect(containerElement.innerHTML).to.equal(renderHtml));

it("should attach a click handler to each item", (): void => {
document.querySelectorAll(`#${container} > li:not([id])`).forEach((element: HTMLLIElement, index: number): void => {
element.dispatchEvent(new MouseEvent("click"));
tap.should.have.been.calledWith(index);
expect(tap).to.have.been.calledWith(index);
});
tap.callCount.should.equal(3);
expect(tap.callCount).to.equal(3);
});
});

Expand All @@ -126,9 +126,11 @@ describe("List", (): void => {

it("should prevent the default touchstart behavour", (): void => {
event = new MouseEvent("touchstart");
sinon.spy(event, "preventDefault");

const preventDefault = sinon.spy(event, "preventDefault");

list["index"].dispatchEvent(event);
event.preventDefault.should.have.been.called;
expect(preventDefault).to.have.been.called;
});

describe("without active button state", (): void => {
Expand All @@ -137,7 +139,7 @@ describe("List", (): void => {
list["index"].dispatchEvent(event);
});

it("should do nothing", (): Chai.Assertion => scrollIntoView.should.not.have.been.called);
it("should do nothing", (): Chai.Assertion => expect(scrollIntoView).to.not.have.been.called);
});

describe("with active button state", (): void => {
Expand All @@ -157,7 +159,7 @@ describe("List", (): void => {
list["index"].dispatchEvent(event);
});

it("should do nothing", (): Chai.Assertion => scrollIntoView.should.not.have.been.called);
it("should do nothing", (): Chai.Assertion => expect(scrollIntoView).to.not.have.been.called);
});

describe("element not within index", (): void => {
Expand All @@ -167,7 +169,7 @@ describe("List", (): void => {
list["index"].dispatchEvent(event);
});

it("should do nothing", (): Chai.Assertion => scrollIntoView.should.not.have.been.called);
it("should do nothing", (): Chai.Assertion => expect(scrollIntoView).to.not.have.been.called);
});

describe("element within index", (): void => {
Expand All @@ -177,7 +179,7 @@ describe("List", (): void => {
list["index"].dispatchEvent(event);
});

it("should scroll the corresponding group into view", (): Chai.Assertion => scrollIntoView.should.have.been.calledWith(true));
it("should scroll the corresponding group into view", (): Chai.Assertion => expect(scrollIntoView).to.have.been.calledWith(true));
});

afterEach((): void => {
Expand All @@ -199,7 +201,7 @@ describe("List", (): void => {
list.showIndex();
});

it("should show the index", (): Chai.Assertion => index.style.display.should.equal("block"));
it("should show the index", (): Chai.Assertion => expect(index.style.display).to.equal("block"));

afterEach((): void => index.remove());
});
Expand All @@ -215,7 +217,7 @@ describe("List", (): void => {
list.hideIndex();
});

it("should hide the index", (): Chai.Assertion => index.style.display.should.equal("none"));
it("should hide the index", (): Chai.Assertion => expect(index.style.display).to.equal("none"));

afterEach((): void => index.remove());
});
Expand All @@ -242,22 +244,22 @@ describe("List", (): void => {
describe("item above view", (): void => {
beforeEach((): void => list.scrollTo("1"));

it("should update the scroll position", (): Chai.Assertion => (appController.viewStack.pop() as View).scrollPos.should.equal(20 + BODY_PADDING));
it("should set the scroll position", (): Chai.Assertion => appController.setScrollPosition.should.have.been.called);
it("should update the scroll position", (): Chai.Assertion => expect((appController.viewStack.pop() as View).scrollPos).to.equal(20 + BODY_PADDING));
it("should set the scroll position", (): Chai.Assertion => expect(appController.setScrollPosition).to.have.been.called);
});

describe("item in view", (): void => {
beforeEach((): void => list.scrollTo("5"));

it("should not update the scroll position", (): Chai.Assertion => (appController.viewStack.pop() as View).scrollPos.should.equal(40));
it("should not set the scroll position", (): Chai.Assertion => appController.setScrollPosition.should.not.have.been.called);
it("should not update the scroll position", (): Chai.Assertion => expect((appController.viewStack.pop() as View).scrollPos).to.equal(40));
it("should not set the scroll position", (): Chai.Assertion => expect(appController.setScrollPosition).to.not.have.been.called);
});

describe("item below view", (): void => {
beforeEach((): void => list.scrollTo("8"));

it("should update the scroll position", (): Chai.Assertion => (appController.viewStack.pop() as View).scrollPos.should.equal(80 + BODY_PADDING));
it("should set the scroll position", (): Chai.Assertion => appController.setScrollPosition.should.have.been.called);
it("should update the scroll position", (): Chai.Assertion => expect((appController.viewStack.pop() as View).scrollPos).to.equal(80 + BODY_PADDING));
it("should set the scroll position", (): Chai.Assertion => expect(appController.setScrollPosition).to.have.been.called);
});
});

Expand All @@ -271,23 +273,23 @@ describe("List", (): void => {
describe(validAction, (): void => {
beforeEach((): void => list.setAction(validAction));

it("should set the action", (): Chai.Assertion => (list["action"] as ListAction).should.equal(validAction));
it("should set the action", (): Chai.Assertion => expect(list["action"] as ListAction).to.equal(validAction));

if ("view" === validAction) {
it("should not save the scroll position", (): Chai.Assertion => appController.getScrollPosition.should.not.have.been.called);
it("should not save the scroll position", (): Chai.Assertion => expect(appController.getScrollPosition).to.not.have.been.called);
} else {
it("should save the scroll position", (): Chai.Assertion => appController.getScrollPosition.should.have.been.called);
it("should save the scroll position", (): Chai.Assertion => expect(appController.getScrollPosition).to.have.been.called);
}

it("should not show an alert", (): Chai.Assertion => WindowMock.alert.should.not.have.been.called);
it("should not show an alert", (): Chai.Assertion => expect(WindowMock.alert).to.not.have.been.called);
});
});

describe("invalid action", (): void => {
beforeEach((): void => list.setAction("invalid" as ListAction));
it("should not save the scroll position", (): Chai.Assertion => appController.getScrollPosition.should.not.have.been.called);
it("should show an alert", (): Chai.Assertion => WindowMock.alert.should.have.been.calledWith("invalid is not a valid action"));
it("should not set the action", (): Chai.Assertion => (undefined === list["action"]).should.be.true);
it("should not save the scroll position", (): Chai.Assertion => expect(appController.getScrollPosition).to.not.have.been.called);
it("should show an alert", (): Chai.Assertion => expect(WindowMock.alert).to.have.been.calledWith("invalid is not a valid action"));
it("should not set the action", (): Chai.Assertion => expect(list["action"]).to.be.undefined);
});
});

Expand All @@ -313,8 +315,8 @@ describe("List", (): void => {
list["tap"](0);
});

it("should not trigger a confirm prompt", (): Chai.Assertion => WindowMock.confirm.should.not.have.been.called);
it("should not trigger the event handler", (): Chai.Assertion => eventHandler.should.not.have.been.called);
it("should not trigger a confirm prompt", (): Chai.Assertion => expect(WindowMock.confirm).to.not.have.been.called);
it("should not trigger the event handler", (): Chai.Assertion => expect(eventHandler).to.not.have.been.called);
});
}

Expand All @@ -332,8 +334,8 @@ describe("List", (): void => {
list["tap"](0);
});

it("should trigger a confirm prompt", (): Chai.Assertion => WindowMock.confirm.should.have.been.calledWith("Delete this item?"));
it("should trigger the event handler", (): Chai.Assertion => eventHandler.should.have.been.called);
it("should trigger a confirm prompt", (): Chai.Assertion => expect(WindowMock.confirm).to.have.been.calledWith("Delete this item?"));
it("should trigger the event handler", (): Chai.Assertion => expect(eventHandler).to.have.been.called);
});

describe("aborted", (): void => {
Expand All @@ -343,17 +345,17 @@ describe("List", (): void => {
list["tap"](0);
});

it("should trigger a confirm prompt", (): Chai.Assertion => WindowMock.confirm.should.have.been.calledWith("Delete this item?"));
it("should not trigger the event handler", (): Chai.Assertion => eventHandler.should.not.have.been.called);
it("should trigger a confirm prompt", (): Chai.Assertion => expect(WindowMock.confirm).to.have.been.calledWith("Delete this item?"));
it("should not trigger the event handler", (): Chai.Assertion => expect(eventHandler).to.not.have.been.called);
});
} else {
beforeEach((): void => {
list["action"] = validAction;
list["tap"](0);
});

it("should not trigger a confirm prompt", (): Chai.Assertion => WindowMock.confirm.should.not.have.been.called);
it("should trigger the event handler", (): Chai.Assertion => eventHandler.should.have.been.called);
it("should not trigger a confirm prompt", (): Chai.Assertion => expect(WindowMock.confirm).to.not.have.been.called);
it("should trigger the event handler", (): Chai.Assertion => expect(eventHandler).to.have.been.called);
}
});
});
Expand All @@ -365,8 +367,8 @@ describe("List", (): void => {
list["tap"](0);
});

it("should not trigger a confirm prompt", (): Chai.Assertion => WindowMock.confirm.should.not.have.been.called);
it("should not trigger the event handler", (): Chai.Assertion => eventHandler.should.not.have.been.called);
it("should not trigger a confirm prompt", (): Chai.Assertion => expect(WindowMock.confirm).to.not.have.been.called);
it("should not trigger the event handler", (): Chai.Assertion => expect(eventHandler).to.not.have.been.called);
});
});

Expand Down
12 changes: 6 additions & 6 deletions spec/public/components/progressbar_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ describe("ProgressBar", (): void => {
});

describe("object constructor", (): void => {
it("should return a ProgressBar instance", (): Chai.Assertion => progressBar.should.be.an.instanceOf(ProgressBar));
it("should set the total", (): Chai.Assertion => progressBar["total"].should.equal(total));
it("should set the sections", (): Chai.Assertion => progressBar["sections"].should.equal(sections));
it("should return a ProgressBar instance", (): Chai.Assertion => expect(progressBar).to.be.an.instanceOf(ProgressBar));
it("should set the total", (): Chai.Assertion => expect(progressBar["total"]).to.equal(total));
it("should set the sections", (): Chai.Assertion => expect(progressBar["sections"]).to.equal(sections));
});

describe("setSection", (): void => {
Expand All @@ -31,15 +31,15 @@ describe("ProgressBar", (): void => {
style: "style-two"
});
sections.forEach((section: Section, index: number): string => progressBar.setSection(index, section));
progressBar["sections"].should.deep.equal(sections);
expect(progressBar["sections"]).to.deep.equal(sections);
});
});

describe("setTotal", (): void => {
it("should set the total", (): void => {
total = 2;
progressBar.setTotal(total);
progressBar["total"].should.equal(total);
expect(progressBar["total"]).to.equal(total);
});
});

Expand Down Expand Up @@ -86,7 +86,7 @@ describe("ProgressBar", (): void => {
scenarios.forEach((scenario: Scenario): void => {
it(`should return html with ${scenario.description}`, (): void => {
progressBar = new ProgressBar(scenario.total, scenario.sections);
progressBar["render"]().should.equal(scenario.result);
expect(progressBar["render"]()).to.equal(scenario.result);
});
});
});
Expand Down
36 changes: 18 additions & 18 deletions spec/public/controllers/about-controller_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ describe("AboutController", (): void => {
beforeEach((): AboutController => (aboutController = new AboutController()));

describe("object constructor", (): void => {
it("should return an AboutController instance", (): Chai.Assertion => aboutController.should.be.an.instanceOf(AboutController));
it("should return an AboutController instance", (): Chai.Assertion => expect(aboutController).to.be.an.instanceOf(AboutController));
});

describe("view", (): void => {
it("should return the about view", (): Chai.Assertion => aboutController.view.should.equal(AboutView));
it("should return the about view", (): Chai.Assertion => expect(aboutController.view).to.equal(AboutView));
});

describe("setup", (): void => {
Expand All @@ -50,34 +50,34 @@ describe("AboutController", (): void => {
leftButton = aboutController.header.leftButton as NavButton;
});

it("should set the header label", (): Chai.Assertion => String(aboutController.header.label).should.equal("About"));
it("should set the header label", (): Chai.Assertion => expect(String(aboutController.header.label)).to.equal("About"));

it("should attach a header left button event handler", (): void => {
(leftButton.eventHandler as NavButtonEventHandler)();
aboutController["goBack"].should.have.been.called;
expect(aboutController["goBack"]).to.have.been.called;
});

it("should set the header left button style", (): Chai.Assertion => String(leftButton.style).should.equal("backButton"));
it("should set the header left button label", (): Chai.Assertion => leftButton.label.should.equal("Settings"));
it("should set the header left button style", (): Chai.Assertion => expect(String(leftButton.style)).to.equal("backButton"));
it("should set the header left button label", (): Chai.Assertion => expect(leftButton.label).to.equal("Settings"));

it("should set the total number of programs", (): void => {
ProgramMock.count.should.have.been.called;
totalPrograms.value.should.equal("1");
expect(ProgramMock.count).to.have.been.called;
expect(totalPrograms.value).to.equal("1");
});

it("should get the total number of series", (): void => {
SeriesMock.count.should.have.been.called;
totalSeries.value.should.equal("1");
expect(SeriesMock.count).to.have.been.called;
expect(totalSeries.value).to.equal("1");
});

it("should get the total number of episodes", (): void => {
EpisodeMock.totalCount.should.have.been.called;
EpisodeMock.countByStatus.should.have.been.calledWith("Watched");
totalEpisodes.value.should.equal("1 (100.00% watched)");
expect(EpisodeMock.totalCount).to.have.been.called;
expect(EpisodeMock.countByStatus).to.have.been.calledWith("Watched");
expect(totalEpisodes.value).to.equal("1 (100.00% watched)");
});

it("should set the database version", (): Chai.Assertion => databaseVersion.value.should.equal("v1"));
it("should set the scroll position", (): Chai.Assertion => appController.setScrollPosition.should.have.been.called);
it("should set the database version", (): Chai.Assertion => expect(databaseVersion.value).to.equal("v1"));
it("should set the scroll position", (): Chai.Assertion => expect(appController.setScrollPosition).to.have.been.called);

afterEach((): void => {
databaseVersion.remove();
Expand All @@ -90,17 +90,17 @@ describe("AboutController", (): void => {
describe("goBack", (): void => {
it("should pop the view", async (): Promise<void> => {
await aboutController["goBack"]();
appController.popView.should.have.been.called;
expect(appController.popView).to.have.been.called;
});
});

describe("watchedPercent", (): void => {
describe("no episodes", (): void => {
it("should return the watched percent as zero", (): Chai.Assertion => aboutController["watchedPercent"](0, 1).should.equal("0 (0% watched)"));
it("should return the watched percent as zero", (): Chai.Assertion => expect(aboutController["watchedPercent"](0, 1)).to.equal("0 (0% watched)"));
});

describe("with episodes", (): void => {
it("should return the watched percent as non-zero", (): Chai.Assertion => aboutController["watchedPercent"](2, 1).should.equal("2 (50.00% watched)"));
it("should return the watched percent as non-zero", (): Chai.Assertion => expect(aboutController["watchedPercent"](2, 1)).to.equal("2 (50.00% watched)"));
});
});
});
Loading

0 comments on commit 0046e11

Please sign in to comment.