Migrate some tests to React Testing Library (#9584)
This commit is contained in:
parent
ef548a4843
commit
38dbe8ed33
12 changed files with 325 additions and 527 deletions
|
@ -15,8 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import React from 'react';
|
||||
// eslint-disable-next-line deprecate/import
|
||||
import { mount } from 'enzyme';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import SettingsStore from '../../../../src/settings/SettingsStore';
|
||||
import UiFeatureSettingWrapper from '../../../../src/components/views/settings/UiFeatureSettingWrapper';
|
||||
|
@ -29,29 +28,29 @@ describe('<UiFeatureSettingWrapper>', () => {
|
|||
uiFeature: UIFeature.Feedback,
|
||||
children: <div>test</div>,
|
||||
};
|
||||
const getComponent = (props = {}) => mount(<UiFeatureSettingWrapper {...defaultProps} {...props} />);
|
||||
const getComponent = (props = {}) => render(<UiFeatureSettingWrapper {...defaultProps} {...props} />);
|
||||
|
||||
beforeEach(() => {
|
||||
(SettingsStore.getValue as jest.Mock).mockClear().mockReturnValue(true);
|
||||
});
|
||||
|
||||
it('renders children when setting is truthy', () => {
|
||||
const component = getComponent();
|
||||
const { asFragment } = getComponent();
|
||||
|
||||
expect(component).toMatchSnapshot();
|
||||
expect(asFragment()).toMatchSnapshot();
|
||||
expect(SettingsStore.getValue).toHaveBeenCalledWith(defaultProps.uiFeature);
|
||||
});
|
||||
|
||||
it('returns null when setting is truthy but children are undefined', () => {
|
||||
const component = getComponent({ children: undefined });
|
||||
const { asFragment } = getComponent({ children: undefined });
|
||||
|
||||
expect(component.html()).toBeNull();
|
||||
expect(asFragment()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('returns null when setting is falsy', () => {
|
||||
(SettingsStore.getValue as jest.Mock).mockReturnValue(false);
|
||||
const component = getComponent();
|
||||
const { asFragment } = getComponent();
|
||||
|
||||
expect(component.html()).toBeNull();
|
||||
expect(asFragment()).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue