Skip to content

Commit

Permalink
[test] Use method calls over property access expressions (#20545)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Apr 14, 2020
1 parent 73a5ddd commit a4fb7b4
Show file tree
Hide file tree
Showing 38 changed files with 312 additions and 303 deletions.
2 changes: 0 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ module.exports = {
rules: {
// does not work with wildcard imports. Mistakes will throw at runtime anyway
'import/named': 'off',
// for expect style assertions
'no-unused-expressions': 'off',

// no rationale provided in /recommended
'mocha/no-mocha-arrows': 'off',
Expand Down
58 changes: 29 additions & 29 deletions packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,13 @@ describe('<Autocomplete />', () => {

// listbox is not only inaccessible but not in the DOM
const listbox = queryByRole('listbox', { hidden: true });
expect(listbox).to.be.null;
expect(listbox).to.equal(null);

const buttons = getAllByRole('button');
expect(buttons).to.have.length(2);
expect(buttons[0]).to.have.accessibleName('Clear');
expect(buttons[0]).toHaveAccessibleName('Clear');
expect(buttons[0]).to.have.attribute('title', 'Clear');
expect(buttons[1]).to.have.accessibleName('Open');
expect(buttons[1]).toHaveAccessibleName('Open');
expect(buttons[1]).to.have.attribute('title', 'Open');
buttons.forEach((button) => {
expect(button, 'button is not in tab order').to.have.property('tabIndex', -1);
Expand Down Expand Up @@ -396,9 +396,9 @@ describe('<Autocomplete />', () => {

const buttons = getAllByRole('button');
expect(buttons).to.have.length(2);
expect(buttons[0]).to.have.accessibleName('Clear');
expect(buttons[0]).toHaveAccessibleName('Clear');
expect(buttons[0]).to.have.attribute('title', 'Clear');
expect(buttons[1]).to.have.accessibleName('Close');
expect(buttons[1]).toHaveAccessibleName('Close');
expect(buttons[1]).to.have.attribute('title', 'Close');
buttons.forEach((button) => {
expect(button, 'button is not in tab order').to.have.property('tabIndex', -1);
Expand Down Expand Up @@ -595,20 +595,20 @@ describe('<Autocomplete />', () => {
const combobox = getByRole('combobox');

expect(combobox).to.have.attribute('aria-expanded', 'true');
expect(textbox).to.have.focus;
expect(textbox).toHaveFocus();

fireEvent.mouseDown(textbox);
fireEvent.click(textbox);
expect(combobox).to.have.attribute('aria-expanded', 'false');

document.activeElement.blur();
expect(combobox).to.have.attribute('aria-expanded', 'false');
expect(textbox).to.not.have.focus;
expect(textbox).not.toHaveFocus();

fireEvent.mouseDown(textbox);
fireEvent.click(textbox);
expect(combobox).to.have.attribute('aria-expanded', 'true');
expect(textbox).to.have.focus;
expect(textbox).toHaveFocus();

fireEvent.mouseDown(textbox);
fireEvent.click(textbox);
Expand All @@ -629,7 +629,7 @@ describe('<Autocomplete />', () => {
fireEvent.keyDown(document.activeElement, { key: 'ArrowUp' });

const options = getAllByRole('option');
expect(document.activeElement).to.have.focus;
expect(document.activeElement).toHaveFocus();
expect(document.activeElement).to.have.attribute(
'aria-activedescendant',
options[options.length - 1].getAttribute('id'),
Expand All @@ -648,7 +648,7 @@ describe('<Autocomplete />', () => {
fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });

const options = getAllByRole('option');
expect(document.activeElement).to.have.focus;
expect(document.activeElement).toHaveFocus();
expect(document.activeElement).to.have.attribute(
'aria-activedescendant',
options[0].getAttribute('id'),
Expand All @@ -668,7 +668,7 @@ describe('<Autocomplete />', () => {
fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });
fireEvent.keyDown(document.activeElement, { key: 'ArrowUp' });

expect(document.activeElement).to.have.focus;
expect(document.activeElement).toHaveFocus();
expect(document.activeElement).not.to.have.attribute('aria-activedescendant');
});

Expand All @@ -684,7 +684,7 @@ describe('<Autocomplete />', () => {
fireEvent.keyDown(document.activeElement, { key: 'ArrowUp' });
fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });

expect(document.activeElement).to.have.focus;
expect(document.activeElement).toHaveFocus();
expect(document.activeElement).not.to.have.attribute('aria-activedescendant');
});
});
Expand All @@ -702,7 +702,7 @@ describe('<Autocomplete />', () => {
fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });
fireEvent.keyDown(document.activeElement, { key: 'ArrowUp' });

expect(document.activeElement).to.have.focus;
expect(document.activeElement).toHaveFocus();
expect(document.activeElement).to.have.attribute(
'aria-activedescendant',
getAllByRole('option')[0].getAttribute('id'),
Expand All @@ -723,7 +723,7 @@ describe('<Autocomplete />', () => {

const textbox = getByRole('textbox');
const options = getAllByRole('option');
expect(textbox).to.have.focus;
expect(textbox).toHaveFocus();
expect(textbox).to.have.attribute(
'aria-activedescendant',
options[options.length - 1].getAttribute('id'),
Expand All @@ -745,7 +745,7 @@ describe('<Autocomplete />', () => {

const textbox = getByRole('textbox');
const options = getAllByRole('option');
expect(textbox).to.have.focus;
expect(textbox).toHaveFocus();
expect(textbox).to.have.attribute(
'aria-activedescendant',
options[options.length - 1].getAttribute('id'),
Expand All @@ -764,7 +764,7 @@ describe('<Autocomplete />', () => {
/>,
);
const input = getByRole('textbox');
expect(input.disabled).to.be.true;
expect(input.disabled).to.equal(true);
});

it('should disable the popup button', () => {
Expand All @@ -776,7 +776,7 @@ describe('<Autocomplete />', () => {
renderInput={(params) => <TextField {...params} />}
/>,
);
expect(queryByTitle('Open').disabled).to.be.true;
expect(queryByTitle('Open').disabled).to.equal(true);
});

it('should not render the clear button', () => {
Expand All @@ -788,7 +788,7 @@ describe('<Autocomplete />', () => {
renderInput={(params) => <TextField {...params} />}
/>,
);
expect(queryByTitle('Clear')).to.be.null;
expect(queryByTitle('Clear')).to.equal(null);
});

it('should not apply the hasClearIcon class', () => {
Expand All @@ -815,7 +815,7 @@ describe('<Autocomplete />', () => {
renderInput={(params) => <TextField {...params} />}
/>,
);
expect(queryByTitle('Clear')).to.be.null;
expect(queryByTitle('Clear')).to.equal(null);
expect(container.querySelector(`.${classes.root}`)).to.have.class(classes.hasPopupIcon);
expect(container.querySelector(`.${classes.root}`)).not.to.have.class(classes.hasClearIcon);
});
Expand Down Expand Up @@ -1092,11 +1092,11 @@ describe('<Autocomplete />', () => {

const textbox = getByRole('textbox');
fireEvent.click(textbox);
expect(textbox).to.have.focus;
expect(textbox).toHaveFocus();
textbox.blur();

fireEvent.click(queryByTitle('Open'));
expect(textbox).to.have.focus;
expect(textbox).toHaveFocus();
});
});

Expand Down Expand Up @@ -1422,16 +1422,16 @@ describe('<Autocomplete />', () => {
);
const textbox = getByRole('textbox');
let firstOption = getByRole('option');
expect(textbox).to.have.focus;
expect(textbox).toHaveFocus();
fireEvent.click(firstOption);
expect(textbox).to.not.have.focus;
expect(textbox).not.toHaveFocus();

fireEvent.click(queryByTitle('Open'));
expect(textbox).to.have.focus;
expect(textbox).toHaveFocus();
firstOption = getByRole('option');
fireEvent.touchStart(firstOption);
fireEvent.click(firstOption);
expect(textbox).to.not.have.focus;
expect(textbox).not.toHaveFocus();
});

it('[blurOnSelect="touch"] should only blur the input when an option is touched', () => {
Expand All @@ -1448,13 +1448,13 @@ describe('<Autocomplete />', () => {
const textbox = getByRole('textbox');
let firstOption = getByRole('option');
fireEvent.click(firstOption);
expect(textbox).to.have.focus;
expect(textbox).toHaveFocus();

fireEvent.click(queryByTitle('Open'));
firstOption = getByRole('option');
fireEvent.touchStart(firstOption);
fireEvent.click(firstOption);
expect(textbox).to.not.have.focus;
expect(textbox).not.toHaveFocus();
});

it('[blurOnSelect="mouse"] should only blur the input when an option is clicked', () => {
Expand All @@ -1472,12 +1472,12 @@ describe('<Autocomplete />', () => {
let firstOption = getByRole('option');
fireEvent.touchStart(firstOption);
fireEvent.click(firstOption);
expect(textbox).to.have.focus;
expect(textbox).toHaveFocus();

fireEvent.click(queryByTitle('Open'));
firstOption = getByRole('option');
fireEvent.click(firstOption);
expect(textbox).to.not.have.focus;
expect(textbox).not.toHaveFocus();
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-lab/src/Pagination/Pagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('<Pagination />', () => {
const [, page1] = getAllByRole('button');
expect(page1).to.have.attribute('aria-current', 'true');
// verifying no regression from previous bug where `page` wasn't intercepted
expect(container.querySelector('[page]')).to.be.null;
expect(container.querySelector('[page]')).to.equal(null);
});

it('fires onChange when a different page is clicked', () => {
Expand Down
Loading

0 comments on commit a4fb7b4

Please sign in to comment.