feat: migrate enzyme to RTL (#770)

This commit is contained in:
Syed Ali Abbas Zaidi
2024-01-25 02:57:28 +05:00
committed by GitHub
parent 6d431e5746
commit 34fbadfd6a
9 changed files with 627 additions and 359 deletions

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { shallow } from 'enzyme';
import { shallow } from '@edx/react-unit-test-utils';
import EditorContainer from './EditorContainer';
jest.mock('@edx/frontend-lib-content-components', () => ({ EditorPage: () => 'HeaderTitle' }));
@@ -17,7 +17,7 @@ const props = { courseId: 'cOuRsEId' };
describe('Editor Container', () => {
describe('snapshots', () => {
test('rendering correctly with expected Input', () => {
expect(shallow(<EditorContainer {...props} />)).toMatchSnapshot();
expect(shallow(<EditorContainer {...props} />).snapshot).toMatchSnapshot();
});
});
});

View File

@@ -1,14 +1,14 @@
import React from 'react';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import { Helmet } from 'react-helmet';
import { mount } from 'enzyme';
import { render } from '@testing-library/react';
import { getConfig } from '@edx/frontend-platform';
import Head from './Head';
describe('Head', () => {
const props = {};
it('should match render title tag and favicon with the site configuration values', () => {
mount(<IntlProvider locale="en"><Head {...props} /></IntlProvider>);
render(<IntlProvider locale="en"><Head {...props} /></IntlProvider>);
const helmet = Helmet.peek();
expect(helmet.title).toEqual(`Course Authoring | ${getConfig().SITE_NAME}`);
expect(helmet.linkTags[0].rel).toEqual('shortcut icon');

View File

@@ -1,4 +1,4 @@
import { shallow } from 'enzyme';
import { shallow } from '@edx/react-unit-test-utils';
import ORASettings from './Settings';
jest.mock('@edx/frontend-platform/i18n', () => ({
@@ -28,6 +28,6 @@ const props = {
describe('ORASettings', () => {
it('should render', () => {
const wrapper = shallow(<ORASettings {...props} />);
expect(wrapper).toMatchSnapshot();
expect(wrapper.snapshot).toMatchSnapshot();
});
});

View File

@@ -36,6 +36,6 @@ exports[`ORASettings should render 1`] = `
}
}
>
<Component />
[Function]
</AppSettingsModal>
`;

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { shallow } from 'enzyme';
import { shallow } from '@edx/react-unit-test-utils';
import VideoSelectorContainer from './VideoSelectorContainer';
jest.mock('@edx/frontend-lib-content-components', () => ({ VideoSelectorPage: () => 'HeaderTitle' }));
@@ -17,7 +17,7 @@ const props = { courseId: 'cOuRsEId' };
describe('Video Selector Container', () => {
describe('snapshots', () => {
test('rendering correctly with expected Input', () => {
expect(shallow(<VideoSelectorContainer {...props} />)).toMatchSnapshot();
expect(shallow(<VideoSelectorContainer {...props} />).snapshot).toMatchSnapshot();
});
});
});

View File

@@ -4,14 +4,10 @@ import '@testing-library/jest-dom';
import '@testing-library/jest-dom/extend-expect';
/* eslint-disable import/no-extraneous-dependencies */
import Enzyme from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import 'babel-polyfill';
import { mergeConfig } from '@edx/frontend-platform';
Enzyme.configure({ adapter: new Adapter() });
/* need to mock window for tinymce on import, as it is JSDOM incompatible */
Object.defineProperty(window, 'matchMedia', {