Skip to content

Commit

Permalink
Remove incorrect usage of expect.toBeDefined
Browse files Browse the repository at this point in the history
  • Loading branch information
ecraig12345 committed Oct 22, 2020
1 parent 0014d1f commit 19ec826
Show file tree
Hide file tree
Showing 23 changed files with 79 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('DatePicker', () => {
const datePicker = mount(<DatePickerBase isRequired={true} allowTextInput={true} onSelectDate={onSelectDate} />);
const textField = datePicker.find('input');

expect(textField).toBeDefined();
expect(textField).toHaveLength(1);

textField.simulate('change', { target: { value: 'Jan 1 2030' } }).simulate('blur');
textField.simulate('change', { target: { value: '' } }).simulate('blur');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('SelectedItemsList', () => {
]}
/>,
);
expect(wrapper).toBeDefined();
expect(wrapper.exists()).toBeTruthy();
expect(wrapper.find('div').length).toEqual(3);
expect(
wrapper
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('SelectedItemsList', () => {
onItemsRemoved={removeItems}
/>,
);
expect(wrapper).toBeDefined();
expect(wrapper.exists()).toBeTruthy();
expect(wrapper.find('div').length).toEqual(3);
expect(
wrapper
Expand All @@ -102,7 +102,7 @@ describe('SelectedItemsList', () => {
]}
/>,
);
expect(wrapper).toBeDefined();
expect(wrapper.exists()).toBeTruthy();
expect(wrapper.find('div').length).toEqual(3);
expect(
wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,8 @@ describe('Button', () => {
expect(button.getAttribute('aria-label')).toBeNull();

expect(button.getAttribute('aria-labelledby')).toEqual(button.querySelector(`.ms-Button-label`)!.id);
expect(button.getAttribute('aria-labelledby')).toBeDefined();

expect(button.getAttribute('aria-describedby')).toEqual(button.querySelector('.some-screenreader-class')!.id);
expect(button.getAttribute('aria-describedby')).toBeDefined();
});

it('applies aria-describedby to an IconButton', () => {
Expand All @@ -226,10 +224,8 @@ describe('Button', () => {
expect(button.getAttribute('aria-label')).toBeNull();

expect(button.getAttribute('aria-labelledby')).toBeNull();
expect(button.getAttribute('aria-labelledby')).toBeDefined();

expect(button.getAttribute('aria-describedby')).toEqual(button.querySelector('.some-screenreader-class')!.id);
expect(button.getAttribute('aria-describedby')).toBeDefined();
});

it('applies aria-labelledby and aria-describedby to a CompoundButton with ariaDescription', () => {
Expand All @@ -246,10 +242,8 @@ describe('Button', () => {
expect(button.getAttribute('aria-label')).toBeNull();

expect(button.getAttribute('aria-labelledby')).toEqual(button.querySelector('.ms-Button-label')!.id);
expect(button.getAttribute('aria-labelledby')).toBeDefined();

expect(button.getAttribute('aria-describedby')).toEqual(button.querySelector('.some-screenreader-class')!.id);
expect(button.getAttribute('aria-describedby')).toBeDefined();
});

it(
Expand All @@ -263,10 +257,8 @@ describe('Button', () => {
expect(button.getAttribute('aria-label')).toBeNull();

expect(button.getAttribute('aria-labelledby')).toEqual(button.querySelector('.ms-Button-label')!.id);
expect(button.getAttribute('aria-labelledby')).toBeDefined();

expect(button.getAttribute('aria-describedby')).toEqual(button.querySelector('.ms-Button-description')!.id);
expect(button.getAttribute('aria-describedby')).toBeDefined();
},
);

Expand Down Expand Up @@ -983,15 +975,14 @@ describe('Button', () => {

const button = render(element);

expect(button).toBeDefined();
ReactTestUtils.Simulate.click(button);

// get the menu id from the button's aria attribute
const menuId = button.getAttribute('aria-owns');
expect(menuId).toBeDefined();
expect(menuId).toBeTruthy();

const menuDOM = button.ownerDocument!.getElementById(menuId as string);
expect(menuDOM).toBeDefined();
expect(menuDOM).toBeTruthy();

return menuDOM as HTMLElement;
}
Expand All @@ -1001,7 +992,7 @@ describe('Button', () => {

expect(contextualMenuElement).not.toBeNull();
expect(contextualMenuElement.getAttribute('aria-label')).toBeNull();
expect(contextualMenuElement.getAttribute('aria-labelledBy')).toBeDefined();
expect(contextualMenuElement.getAttribute('aria-labelledBy')).toBeTruthy();
});

it('If button has a text child, contextual menu has aria-labelledBy attribute set', () => {
Expand Down Expand Up @@ -1048,12 +1039,11 @@ describe('Button', () => {

const button = render(element);

expect(button).toBeDefined();
ReactTestUtils.Simulate.click(button);

// get the menu id from the button's aria attribute
const menuId = button.getAttribute('aria-owns');
expect(menuId).toBeDefined();
expect(menuId).toBeTruthy();

const contextualMenuElement = button.ownerDocument!.getElementById(menuId as string);
expect(contextualMenuElement).not.toBeNull();
Expand Down
12 changes: 2 additions & 10 deletions packages/react-internal/src/components/Calendar/Calendar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ describe('Calendar', () => {
renderedComponent,
'ms-DatePicker-monthAndYear',
);
expect(dayPickerMonth).toBeDefined();
expect(dayPickerMonth.textContent).toEqual(monthName + ' ' + year.toString());
});

Expand Down Expand Up @@ -118,7 +117,6 @@ describe('Calendar', () => {

it('Verify go to today', () => {
const goToToday = ReactTestUtils.findRenderedDOMComponentWithClass(renderedComponent, 'ms-DatePicker-goToday');
expect(goToToday).toBeDefined();
expect(goToToday.textContent).toEqual(dayPickerStrings.goToToday);
});
});
Expand Down Expand Up @@ -156,7 +154,6 @@ describe('Calendar', () => {
renderedComponent,
'ms-DatePicker-monthAndYear',
);
expect(dayPickerMonth).toBeDefined();
expect(dayPickerMonth.textContent).toEqual(monthName + ' ' + defaultDate.getFullYear().toString());
});

Expand All @@ -182,7 +179,6 @@ describe('Calendar', () => {
renderedComponent,
'ms-DatePicker-monthPicker',
) as HTMLElement;
expect(monthPicker).toBeDefined();
expect(monthPicker.style.display).not.toEqual('none');
});

Expand All @@ -191,7 +187,6 @@ describe('Calendar', () => {
renderedComponent,
'ms-DatePicker-currentYear',
);
expect(currentYear).toBeDefined();
expect(currentYear.textContent).toEqual(defaultDate.getFullYear().toString());
});

Expand All @@ -205,7 +200,6 @@ describe('Calendar', () => {

it('Verify go to today', () => {
const goToToday = ReactTestUtils.findRenderedDOMComponentWithClass(renderedComponent, 'ms-DatePicker-goToday');
expect(goToToday).toBeDefined();
expect(goToToday.textContent).toEqual(dayPickerStrings.goToToday);
});

Expand All @@ -232,11 +226,9 @@ describe('Calendar', () => {

it('Verify class name', () => {
const calendarRoot = ReactTestUtils.scryRenderedDOMComponentsWithClass(renderedComponent, 'CalendarTestClass');
expect(calendarRoot).toBeDefined();
expect(calendarRoot.length).toEqual(1);
expect(calendarRoot).toHaveLength(1);
const root = calendarRoot[0];
expect(root.classList).toBeDefined();
expect(root.classList.length).toEqual(2);
expect(root.classList).toHaveLength(2);
expect(root.classList[0]).toEqual('ms-DatePicker');
expect(root.classList[1]).toEqual('CalendarTestClass');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('ChoiceGroup', () => {
it('does not use className prop from parent on label', () => {
choiceGroup = mount(<ChoiceGroup className="testClassName" label="test label" options={TEST_OPTIONS} required />);
const label = choiceGroup.getDOMNode().querySelector('label');
expect(label).toBeDefined();
expect(label).toBeTruthy();
expect(label!.textContent).toBe('test label');
expect(label!.className).not.toContain('testClassName');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('ColorRectangle', () => {
const descriptionId = element.getAttribute('aria-describedby');
expect(descriptionId).toBeTruthy();
const descriptionEl = element.querySelectorAll('#' + descriptionId)[0];
expect(descriptionEl).toBeDefined();
expect(descriptionEl).toBeTruthy();
expect(descriptionEl.textContent).toBe(
'Use left and right arrow keys to set saturation. Use up and down arrow keys to set brightness.',
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('CommandBar', () => {

menuItem.simulate('click');

expect(document.querySelector('.SubMenuClass')).toBeDefined();
expect(document.querySelector('.SubMenuClass')).toBeTruthy();
});

it('keeps menu open after update if item is still present', () => {
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('CommandBar', () => {
menuItem.simulate('click');

// Make sure the menu is open before the re-render
expect(document.querySelector('.SubMenuClass')).toBeDefined();
expect(document.querySelector('.SubMenuClass')).toBeTruthy();

// Update the props, and re-render
commandBar.setProps({
Expand All @@ -100,7 +100,7 @@ describe('CommandBar', () => {
});

// Make sure the menu is still open after the re-render
expect(document.querySelector('.SubMenuClass')).toBeDefined();
expect(document.querySelector('.SubMenuClass')).toBeTruthy();
});

it('closes menu after update if item is not longer present', () => {
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('CommandBar', () => {
menuItem.simulate('click');

// Make sure the menu is open before the re-render
expect(document.querySelector('.SubMenuClass')).toBeDefined();
expect(document.querySelector('.SubMenuClass')).toBeTruthy();

// Update the props, and re-render
commandBar.setProps({
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('CommandBar', () => {
menuItem.simulate('click');

// Make sure the menu is open before the re-render
expect(document.querySelector('.SubMenuClass')).toBeDefined();
expect(document.querySelector('.SubMenuClass')).toBeTruthy();

// Update the props
items[0].subMenuProps.items[0].className = 'SubMenuClassUpdate';
Expand All @@ -175,6 +175,6 @@ describe('CommandBar', () => {
});

// Make sure the menu is still open after the re-render
expect(document.querySelector('.SubMenuClassUpdate')).toBeDefined();
expect(document.querySelector('.SubMenuClassUpdate')).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('CommandBar', () => {

menuItem.simulate('click');

expect(document.querySelector('.SubMenuClass')).toBeDefined();
expect(document.querySelector('.SubMenuClass')).toBeTruthy();
});

it('passes event and item to button onClick callbacks', () => {
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('CommandBar', () => {
menuItem.simulate('click');

// Make sure the menu is open before the re-render
expect(document.querySelector('.SubMenuClass')).toBeDefined();
expect(document.querySelector('.SubMenuClass')).toBeTruthy();

// Update the props, and re-render
commandBar.setProps({
Expand All @@ -150,7 +150,7 @@ describe('CommandBar', () => {
});

// Make sure the menu is still open after the re-render
expect(document.querySelector('.SubMenuClass')).toBeDefined();
expect(document.querySelector('.SubMenuClass')).toBeTruthy();
});

it('closes menu after update if item is not longer present', () => {
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('CommandBar', () => {
menuItem.simulate('click');

// Make sure the menu is open before the re-render
expect(document.querySelector('.SubMenuClass')).toBeDefined();
expect(document.querySelector('.SubMenuClass')).toBeTruthy();

// Update the props, and re-render
commandBar.setProps({
Expand Down Expand Up @@ -254,7 +254,7 @@ describe('CommandBar', () => {
menuItem.simulate('click');

// Make sure the menu is open before the re-render
expect(document.querySelector('.SubMenuClass')).toBeDefined();
expect(document.querySelector('.SubMenuClass')).toBeTruthy();

// Update the props
items[0].subMenuProps.items[0].className = 'SubMenuClassUpdate';
Expand All @@ -265,6 +265,6 @@ describe('CommandBar', () => {
});

// Make sure the menu is still open after the re-render
expect(document.querySelector('.SubMenuClassUpdate')).toBeDefined();
expect(document.querySelector('.SubMenuClassUpdate')).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ describe('ContextualMenu', () => {
const header = document.querySelector('.headerFoo') as HTMLElement;
const title = document.querySelector('.titleFoo') as HTMLElement;

expect(container).toBeDefined();
expect(rootEl).toBeDefined();
expect(list).toBeDefined();
expect(header).toBeDefined();
expect(title).toBeDefined();
expect(container).toBeTruthy();
expect(rootEl).toBeTruthy();
expect(list).toBeTruthy();
expect(header).toBeTruthy();
expect(title).toBeTruthy();
});

it('applies in-line style property if present on ContextualMenuItem', () => {
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('ContextualMenu', () => {
ReactTestUtils.Simulate.keyDown(menuItem, { which: KeyCodes.right });
});

expect(document.querySelector('.SubMenuClass')).toBeDefined();
expect(document.querySelector('.SubMenuClass')).toBeTruthy();
});
});

Expand Down Expand Up @@ -291,7 +291,7 @@ describe('getItemClassNames', () => {
iconClassName,
);

expect(itemClassNames).toBeDefined();
expect(itemClassNames).toBeTruthy();
});

it('applies custom classNames to style slots', () => {
Expand Down
Loading

0 comments on commit 19ec826

Please sign in to comment.