Migrate some tests to React Testing Library (#9584)

This commit is contained in:
Germain 2022-11-18 09:16:11 +00:00 committed by GitHub
parent ef548a4843
commit 38dbe8ed33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 325 additions and 527 deletions

View file

@ -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();
});
});