Skip to content

Commit

Permalink
feat: migrate enzyme with RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
Syed-Ali-Abbas-Zaidi committed Nov 30, 2023
1 parent 5e7ac40 commit 1f9a9af
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/components/Footer.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react/prop-types */
import React, { useMemo } from 'react';
import renderer from 'react-test-renderer';
import { mount } from 'enzyme';
import { render, fireEvent, screen } from '@testing-library/react';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import { AppContext } from '@edx/frontend-platform/react';

Expand Down Expand Up @@ -78,9 +78,9 @@ describe('<Footer />', () => {
describe('handles language switching', () => {
it('calls onLanguageSelected prop when a language is changed', () => {
const mockHandleLanguageSelected = jest.fn();
const wrapper = mount(<FooterWithLanguageSelector languageSelected={mockHandleLanguageSelected} />);
render(<FooterWithLanguageSelector languageSelected={mockHandleLanguageSelected} />);

wrapper.find('form').simulate('submit', {
fireEvent.submit(screen.getByTestId("site-footer-submit-btn"), {

Check failure on line 83 in src/components/Footer.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Strings must use singlequote
target: {
elements: {
'site-footer-language-select': {
Expand Down
2 changes: 1 addition & 1 deletion src/components/LanguageSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const LanguageSelector = ({
>
{options.map(({ value, label }) => <option key={value} value={value}>{label}</option>)}
</select>
<button className="btn btn-outline-primary btn-sm" type="submit">
<button data-testid="site-footer-submit-btn" className="btn btn-outline-primary btn-sm" type="submit">
<FormattedMessage
id="footer.languageForm.submit.label"
defaultMessage="Apply"
Expand Down
1 change: 1 addition & 0 deletions src/components/__snapshots__/Footer.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ exports[`<Footer /> renders correctly renders with a language selector 1`] = `
</select>
<button
className="btn btn-outline-primary btn-sm"
data-testid="site-footer-submit-btn"
type="submit"
>
Apply
Expand Down
5 changes: 0 additions & 5 deletions src/setupTest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import Enzyme from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';

Enzyme.configure({ adapter: new Adapter() });

// These configuration values are usually set in webpack's EnvironmentPlugin however
// Jest does not use webpack so we need to set these so for testing
process.env.ACCESS_TOKEN_COOKIE_NAME = 'edx-jwt-cookie-header-payload';
Expand Down

0 comments on commit 1f9a9af

Please sign in to comment.