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

style: simplify test assertions #6983

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/core/test/alert/alertTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe("<Alert>", () => {
cancelButton.simulate("click");
assert.isTrue(onCancel.calledOnce);
assert.isTrue(onClose.calledOnce);
assert.strictEqual(onClose.args[0][0], false);
assert.isFalse(onClose.args[0][0]);
});

it("canEscapeKeyCancel enables escape key", () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/core/test/buttons/buttonTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ function buttonTestSuite(component: React.FC<any>, tagName: string) {
it("wraps string children in spans", () => {
// so text can be hidden when loading
const wrapper = button({}, "raw string", <em>not a string</em>);
assert.equal(wrapper.find("span").length, 1, "span not found");
assert.equal(wrapper.find("em").length, 1, "em not found");
assert.lengthOf(wrapper.find("span"), 1, "span not found");
assert.lengthOf(wrapper.find("em"), 1, "em not found");
});

it("renders span if text={0}", () => {
Expand All @@ -76,12 +76,12 @@ function buttonTestSuite(component: React.FC<any>, tagName: string) {

it('doesn\'t render a text span if children=""', () => {
const wrapper = button({}, "");
assert.equal(wrapper.find("span").length, 0);
assert.lengthOf(wrapper.find("span"), 0);
});

it('doesn\'t render a text span if text=""', () => {
const wrapper = button({ text: "" });
assert.equal(wrapper.find("span").length, 0);
assert.lengthOf(wrapper.find("span"), 0);
});

it("accepts textClassName prop", () => {
Expand Down Expand Up @@ -193,8 +193,8 @@ function buttonTestSuite(component: React.FC<any>, tagName: string) {

// check that the callback was invoked with modifier key flags included
assert.equal(callback.callCount, 1);
assert.equal(callback.firstCall.args[0].shiftKey, true);
assert.equal(callback.firstCall.args[0].metaKey, true);
assert.isTrue(callback.firstCall.args[0].shiftKey);
assert.isTrue(callback.firstCall.args[0].metaKey);
}
});
}
2 changes: 1 addition & 1 deletion packages/core/test/forms/formGroupTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("<FormGroup>", () => {

it("hides label when falsy", () => {
const label = shallow(<FormGroup />).find("label");
assert.strictEqual(label.length, 0);
assert.lengthOf(label, 0);
});

it("labelInfo=JSX renders JSX content in label", () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/test/menu/menuItemTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ describe("MenuItem", () => {
it("can set roleStructure to change role prop structure to that of a listbox or select item", () => {
const wrapper = mount(<MenuItem text="Roles" roleStructure="listoption" />);
assert.equal(wrapper.find("li").prop("role"), "option");
assert.equal(wrapper.find("a").prop("role"), undefined);
assert.isUndefined(wrapper.find("a").prop("role"));
});

it("can set roleStructure to change role prop structure to that of a list item", () => {
const wrapper = mount(<MenuItem text="Roles" roleStructure="listitem" />);
assert.equal(wrapper.find("li").prop("role"), undefined);
assert.equal(wrapper.find("a").prop("role"), undefined);
assert.isUndefined(wrapper.find("li").prop("role"));
assert.isUndefined(wrapper.find("a").prop("role"));
});

it('can set roleStructure to change role prop structure to void li role (set role="none")', () => {
const wrapper = mount(<MenuItem text="Roles" roleStructure="none" />);
assert.equal(wrapper.find("li").prop("role"), "none");
assert.equal(wrapper.find("a").prop("role"), undefined);
assert.isUndefined(wrapper.find("a").prop("role"));
});

it("disabled MenuItem will not show its submenu", () => {
Expand Down
38 changes: 19 additions & 19 deletions packages/core/test/multistep-dialog/multistepDialogTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ describe("<MultistepDialog>", () => {
);
assert.strictEqual(dialog.state("selectedIndex"), 0);
const steps = dialog.find(`.${Classes.DIALOG_STEP_CONTAINER}`);
assert.strictEqual(steps.at(0).find(`.${Classes.ACTIVE}`).length, 1);
assert.strictEqual(steps.at(1).find(`.${Classes.ACTIVE}`).length, 0);
assert.lengthOf(steps.at(0).find(`.${Classes.ACTIVE}`), 1);
assert.lengthOf(steps.at(1).find(`.${Classes.ACTIVE}`), 0);
dialog.unmount();
});

Expand All @@ -73,8 +73,8 @@ describe("<MultistepDialog>", () => {
findButtonWithText(dialog, "Next").simulate("click");
assert.strictEqual(dialog.state("selectedIndex"), 1);
const steps = dialog.find(`.${Classes.DIALOG_STEP_CONTAINER}`);
assert.strictEqual(steps.at(0).find(`.${Classes.DIALOG_STEP_VIEWED}`).length, 1);
assert.strictEqual(steps.at(1).find(`.${Classes.ACTIVE}`).length, 1);
assert.lengthOf(steps.at(0).find(`.${Classes.DIALOG_STEP_VIEWED}`), 1);
assert.lengthOf(steps.at(1).find(`.${Classes.ACTIVE}`), 1);
dialog.unmount();
});

Expand All @@ -89,14 +89,14 @@ describe("<MultistepDialog>", () => {
findButtonWithText(dialog, "Next").simulate("click");
assert.strictEqual(dialog.state("selectedIndex"), 1);
const steps = dialog.find(`.${Classes.DIALOG_STEP_CONTAINER}`);
assert.strictEqual(steps.at(0).find(`.${Classes.DIALOG_STEP_VIEWED}`).length, 1);
assert.strictEqual(steps.at(1).find(`.${Classes.ACTIVE}`).length, 1);
assert.lengthOf(steps.at(0).find(`.${Classes.DIALOG_STEP_VIEWED}`), 1);
assert.lengthOf(steps.at(1).find(`.${Classes.ACTIVE}`), 1);

findButtonWithText(dialog, "Back").simulate("click");
const newSteps = dialog.find(`.${Classes.DIALOG_STEP_CONTAINER}`);
assert.strictEqual(dialog.state("selectedIndex"), 0);
assert.strictEqual(newSteps.at(0).find(`.${Classes.ACTIVE}`).length, 1);
assert.strictEqual(newSteps.at(1).find(`.${Classes.DIALOG_STEP_VIEWED}`).length, 1);
assert.lengthOf(newSteps.at(0).find(`.${Classes.ACTIVE}`), 1);
assert.lengthOf(newSteps.at(1).find(`.${Classes.DIALOG_STEP_VIEWED}`), 1);
dialog.unmount();
});

Expand All @@ -109,9 +109,9 @@ describe("<MultistepDialog>", () => {
);
findButtonWithText(dialog, "Next").simulate("click");
assert.strictEqual(dialog.state("selectedIndex"), 1);
assert.strictEqual(findButtonWithText(dialog, "Back").length, 1);
assert.strictEqual(findButtonWithText(dialog, "Next").length, 0);
assert.strictEqual(findButtonWithText(dialog, "Submit").length, 1);
assert.lengthOf(findButtonWithText(dialog, "Back"), 1);
assert.lengthOf(findButtonWithText(dialog, "Next"), 0);
assert.lengthOf(findButtonWithText(dialog, "Submit"), 1);
dialog.unmount();
});

Expand All @@ -124,9 +124,9 @@ describe("<MultistepDialog>", () => {
);

assert.strictEqual(dialog.state("selectedIndex"), 0);
assert.strictEqual(findButtonWithText(dialog, "Back").length, 0);
assert.strictEqual(findButtonWithText(dialog, "Next").length, 1);
assert.strictEqual(findButtonWithText(dialog, "Submit").length, 0);
assert.lengthOf(findButtonWithText(dialog, "Back"), 0);
assert.lengthOf(findButtonWithText(dialog, "Next"), 1);
assert.lengthOf(findButtonWithText(dialog, "Submit"), 0);
dialog.unmount();
});

Expand All @@ -138,9 +138,9 @@ describe("<MultistepDialog>", () => {
);

assert.strictEqual(dialog.state("selectedIndex"), 0);
assert.strictEqual(findButtonWithText(dialog, "Back").length, 0);
assert.strictEqual(findButtonWithText(dialog, "Next").length, 0);
assert.strictEqual(findButtonWithText(dialog, "Submit").length, 1);
assert.lengthOf(findButtonWithText(dialog, "Back"), 0);
assert.lengthOf(findButtonWithText(dialog, "Next"), 0);
assert.lengthOf(findButtonWithText(dialog, "Submit"), 1);
dialog.unmount();
});

Expand All @@ -158,8 +158,8 @@ describe("<MultistepDialog>", () => {
step.at(0).simulate("click");
const steps = dialog.find(`.${Classes.DIALOG_STEP_CONTAINER}`);
assert.strictEqual(dialog.state("selectedIndex"), 0);
assert.strictEqual(steps.at(0).find(`.${Classes.ACTIVE}`).length, 1);
assert.strictEqual(steps.at(1).find(`.${Classes.DIALOG_STEP_VIEWED}`).length, 1);
assert.lengthOf(steps.at(0).find(`.${Classes.ACTIVE}`), 1);
assert.lengthOf(steps.at(1).find(`.${Classes.DIALOG_STEP_VIEWED}`), 1);
dialog.unmount();
});

Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/panel-stack/panelStackTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe("<PanelStack>", () => {
it("does not have the back button when only a single panel is on the stack", () => {
panelStackWrapper = renderPanelStack({ initialPanel });
const backButton = panelStackWrapper.findClass(Classes.PANEL_STACK_HEADER_BACK);
assert.equal(backButton.length, 0);
assert.lengthOf(backButton, 0);
});

it("assigns the class to TransitionGroup", () => {
Expand Down Expand Up @@ -252,7 +252,7 @@ describe("<PanelStack>", () => {

const panelHeaders = panelStackWrapper.findClass(Classes.HEADING);
assert.exists(panelHeaders);
assert.equal(panelHeaders.length, 1);
assert.lengthOf(panelHeaders, 1);
assert.equal(panelHeaders.at(0).text(), stack[1].title);
});

Expand All @@ -265,7 +265,7 @@ describe("<PanelStack>", () => {

const panelHeaders = panelStackWrapper.findClass(Classes.HEADING);
assert.exists(panelHeaders);
assert.equal(panelHeaders.length, 2);
assert.lengthOf(panelHeaders, 2);
assert.equal(panelHeaders.at(0).text(), stack[0].title);
assert.equal(panelHeaders.at(1).text(), stack[1].title);
});
Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/panel-stack2/panelStack2Tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe("<PanelStack2>", () => {
it("does not have the back button when only a single panel is on the stack", () => {
panelStackWrapper = renderPanelStack({ initialPanel });
const backButton = panelStackWrapper.findClass(Classes.PANEL_STACK2_HEADER_BACK);
assert.equal(backButton.length, 0);
assert.lengthOf(backButton, 0);
});

it("assigns the class to TransitionGroup", () => {
Expand Down Expand Up @@ -252,7 +252,7 @@ describe("<PanelStack2>", () => {

const panelHeaders = panelStackWrapper.findClass(Classes.HEADING);
assert.exists(panelHeaders);
assert.equal(panelHeaders.length, 1);
assert.lengthOf(panelHeaders, 1);
assert.equal(panelHeaders.at(0).text(), stack[1].title);
});

Expand All @@ -266,7 +266,7 @@ describe("<PanelStack2>", () => {

const panelHeaders = panelStackWrapper.findClass(Classes.HEADING);
assert.exists(panelHeaders);
assert.equal(panelHeaders.length, 2);
assert.lengthOf(panelHeaders, 2);
assert.equal(panelHeaders.at(0).text(), stack[0].title);
assert.equal(panelHeaders.at(1).text(), stack[1].title);
});
Expand Down
9 changes: 3 additions & 6 deletions packages/core/test/popover/popoverTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ describe("<Popover>", () => {
it("moves focus to overlay when opened", done => {
function handleOpened() {
assert.notEqual(document.activeElement, document.body, "body element should not have focus");
assert.isTrue(
document.activeElement?.closest(`.${Classes.OVERLAY}`) !== null,
assert.isNotNull(
document.activeElement?.closest(`.${Classes.OVERLAY}`),
"focus should be inside overlay",
);
done();
Expand All @@ -271,10 +271,7 @@ describe("<Popover>", () => {
function handleClosed(wrapper2: PopoverWrapper) {
wrapper2.assertIsOpen(false);
assert.notEqual(document.activeElement, document.body, "body element should not have focus");
assert.isTrue(
document.activeElement?.closest(`.${targetClassName}`) != null,
"focus should be on target",
);
assert.isNotNull(document.activeElement?.closest(`.${targetClassName}`), "focus should be on target");
}

wrapper = renderPopover(commonProps);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/tree/treeTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe("<Tree>", () => {
const tree = renderTree({ contents });
const disabledTreeNode = tree.find(`.${Classes.TREE_NODE}.c0.${Classes.DISABLED}`);

assert.equal(disabledTreeNode.length, 1);
assert.lengthOf(disabledTreeNode, 1);
});

it("icons are rendered correctly if present", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe("<DateRangeInput3>", () => {

it("renders with two InputGroup children", () => {
const component = mount(<DateRangeInput3 {...DATE_FORMAT} />);
expect(component.find(InputGroup).length).to.equal(2);
expect(component.find(InputGroup)).to.have.lengthOf(2);
});

it("passes custom classNames to popover wrapper", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/select/test/multiSelectTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe("<MultiSelect>", () => {
selectedItems: [TOP_100_FILMS[0]],
tagRenderer: film => <strong>{film.title}</strong>,
});
assert.equal(wrapper.find(Tag).find("strong").length, 1);
assert.lengthOf(wrapper.find(Tag).find("strong"), 1);
});

it("only triggers QueryList key up events when focus is on TagInput's <input>", () => {
Expand Down
18 changes: 9 additions & 9 deletions packages/select/test/selectComponentSuite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export function selectComponentSuite<P extends ListItemsProps<Film>, S>(
it("itemRenderer is called for each child", () => {
const wrapper = render(testProps);
// each item is rendered once
assert.equal(wrapper.find(`.${Classes.MENU_ITEM}`).hostNodes().length, 15, "re-render");
assert.lengthOf(wrapper.find(`.${Classes.MENU_ITEM}`).hostNodes(), 15, "re-render");
wrapper.setProps({ query: "1999" });
wrapper.update();
assert.equal(wrapper.find(`.${Classes.MENU_ITEM}`).hostNodes().length, 2, "re-render");
assert.lengthOf(wrapper.find(`.${Classes.MENU_ITEM}`).hostNodes(), 2, "re-render");
});

it("renders noResults when given empty list", () => {
Expand Down Expand Up @@ -222,7 +222,7 @@ export function selectComponentSuite<P extends ListItemsProps<Film>, S>(
assert.lengthOf(findCreateItem(wrapper), 1, "should find createItem");
findInput(wrapper).simulate("keydown", { key: "Enter" });
findInput(wrapper).simulate("keyup", { key: "Enter" });
assert.equal(testCreateProps.onItemSelect.calledTwice, true, "should invoke onItemSelect twice");
assert.isTrue(testCreateProps.onItemSelect.calledTwice, "should invoke onItemSelect twice");
assert.equal(
(testCreateProps.onItemSelect.args[0][0] as Film).title,
"non-existent film name",
Expand All @@ -241,11 +241,11 @@ export function selectComponentSuite<P extends ListItemsProps<Film>, S>(
query: TOP_100_FILMS[0].title,
});
findInput(wrapper).simulate("keydown", { key: "ArrowDown" });
assert.equal(testProps.onActiveItemChange.lastCall.args[0], null);
assert.equal(testProps.onActiveItemChange.lastCall.args[1], true);
assert.isNull(testProps.onActiveItemChange.lastCall.args[0]);
assert.isTrue(testProps.onActiveItemChange.lastCall.args[1]);
findInput(wrapper).simulate("keydown", { key: "ArrowDown" });
assert.equal((testProps.onActiveItemChange.lastCall.args[0] as Film).rank, TOP_100_FILMS[0].rank);
assert.equal(testProps.onActiveItemChange.lastCall.args[1], false);
assert.isFalse(testProps.onActiveItemChange.lastCall.args[1]);
});

it("when create item is rendered, arrow up invokes onActiveItemChange with an `CreateNewItem`", () => {
Expand All @@ -254,11 +254,11 @@ export function selectComponentSuite<P extends ListItemsProps<Film>, S>(
query: TOP_100_FILMS[0].title,
});
findInput(wrapper).simulate("keydown", { key: "ArrowUp" });
assert.equal(testProps.onActiveItemChange.lastCall.args[0], null);
assert.equal(testProps.onActiveItemChange.lastCall.args[1], true);
assert.isNull(testProps.onActiveItemChange.lastCall.args[0]);
assert.isTrue(testProps.onActiveItemChange.lastCall.args[1]);
findInput(wrapper).simulate("keydown", { key: "ArrowUp" });
assert.equal((testProps.onActiveItemChange.lastCall.args[0] as Film).rank, TOP_100_FILMS[0].rank);
assert.equal(testProps.onActiveItemChange.lastCall.args[1], false);
assert.isFalse(testProps.onActiveItemChange.lastCall.args[1]);
});

it("when create item is rendered, updating the query to exactly match one of the items hides the create item", () => {
Expand Down
Loading