', () => {
});
it('adds the correct class when given a fullScreen prop', () => {
- const { container } = render(
);
- expect(container.firstChild).toHaveClass('full-screen-wrapper');
+ render(
);
+ const fccLoader = screen.getByTestId('fcc-loader');
+ expect(fccLoader).toHaveClass('full-screen-wrapper');
});
/**
@@ -22,12 +23,14 @@ describe('
', () => {
*/
it('matches to the default render snapshot', () => {
- const { container } = render(
);
+ const fccLoader = screen.getByTestId('fcc-loader');
+ expect(fccLoader).toMatchSnapshot();
});
it('matches the fullScreen render snapshot', () => {
- const { container } = render(
);
+ const fccLoader = screen.getByTestId('fcc-loader');
+ expect(fccLoader).toMatchSnapshot();
});
});
diff --git a/client/src/components/helpers/loader.tsx b/client/src/components/helpers/loader.tsx
index e39561e7d9..9e5aa9b2aa 100644
--- a/client/src/components/helpers/loader.tsx
+++ b/client/src/components/helpers/loader.tsx
@@ -17,7 +17,10 @@ function Loader({ fullScreen, timeout }: LoaderProps): JSX.Element {
return () => clearTimeout(timerId);
}, [setShowSpinner, showSpinner, timeout]);
return (
-
+
{showSpinner && }
);
diff --git a/client/src/components/landing/Landing.test.js b/client/src/components/landing/Landing.test.js
index b4fe430a57..9e4e5a26b1 100644
--- a/client/src/components/landing/Landing.test.js
+++ b/client/src/components/landing/Landing.test.js
@@ -10,8 +10,8 @@ describe('
', () => {
it('renders when visiting index page and logged out', () => {
const shallow = new ShallowRenderer();
shallow.render(
);
- const result = shallow.getRenderOutput();
- expect(result.type.displayName === 'Landing').toBeTruthy();
+ const view = shallow.getRenderOutput();
+ expect(view.type.displayName === 'Landing').toBeTruthy();
});
});
diff --git a/client/src/components/profile/Profile.test.tsx b/client/src/components/profile/Profile.test.tsx
index b18ce9f08a..224cfd751f 100644
--- a/client/src/components/profile/Profile.test.tsx
+++ b/client/src/components/profile/Profile.test.tsx
@@ -1,5 +1,5 @@
import React from 'react';
-import { render } from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
import Profile from './Profile';
@@ -55,9 +55,9 @@ const notMyProfileProps = {
describe('
', () => {
it('renders the report button on another persons profile', () => {
- const { getByText } = render(
);
+ render(
);
- const reportButton: HTMLElement = getByText('buttons.flag-user');
+ const reportButton: HTMLElement = screen.getByText('buttons.flag-user');
expect(reportButton).toHaveAttribute('href', '/user/string/report-user');
});
diff --git a/client/src/components/profile/components/HeatMap.test.tsx b/client/src/components/profile/components/HeatMap.test.tsx
index 99cf53bea7..61ff1d4649 100644
--- a/client/src/components/profile/components/HeatMap.test.tsx
+++ b/client/src/components/profile/components/HeatMap.test.tsx
@@ -1,5 +1,5 @@
import React from 'react';
-import { render } from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
import HeatMap from './HeatMap';
@@ -41,15 +41,15 @@ describe('
', () => {
*/
it('calculates the correct longest streak', () => {
- const { getByTestId } = render(
);
- expect(getByTestId('longest-streak').textContent).toContain(
+ render(
);
+ expect(screen.getByTestId('longest-streak')).toHaveTextContent(
'profile.longest-streak'
);
});
it('calculates the correct current streak', () => {
- const { getByTestId } = render(
);
- expect(getByTestId('current-streak').textContent).toContain(
+ render(
);
+ expect(screen.getByTestId('current-streak')).toHaveTextContent(
'profile.current-streak'
);
});
diff --git a/client/src/components/profile/components/TimeLine.test.tsx b/client/src/components/profile/components/TimeLine.test.tsx
index 2c57aaedcf..966911d5b9 100644
--- a/client/src/components/profile/components/TimeLine.test.tsx
+++ b/client/src/components/profile/components/TimeLine.test.tsx
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint-disable @typescript-eslint/no-unsafe-call */
import React from 'react';
-import { render } from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
import TimeLine from './TimeLine';
import { useStaticQuery } from 'gatsby';
@@ -45,29 +45,25 @@ beforeEach(() => {
describe('
', () => {
it('Render button when only solution is present', () => {
// @ts-ignore
- const { container } = render(
);
-
- expect(
- container.querySelector('#btn-for-5e46f802ac417301a38fb92b')
- ).toHaveAttribute('href', 'https://github.com/freeCodeCamp/freeCodeCamp');
+ render(
);
+ const showViewButton = screen.getByRole('link', { name: 'buttons.view' });
+ expect(showViewButton).toHaveAttribute(
+ 'href',
+ 'https://github.com/freeCodeCamp/freeCodeCamp'
+ );
});
it('Render button when both githubLink and solution is present', () => {
// @ts-ignore
- const { container } = render(
);
+ render(
);
- const linkList = container.querySelector(
- '#dropdown-for-5e4f5c4b570f7e3a4949899f + ul'
- );
- // @ts-ignore
- const links = linkList.querySelectorAll('a');
-
- expect(links[0]).toHaveAttribute(
+ const menuItems = screen.getAllByRole('menuitem');
+ expect(menuItems).toHaveLength(2);
+ expect(menuItems[0]).toHaveAttribute(
'href',
'https://github.com/freeCodeCamp/freeCodeCamp1'
);
-
- expect(links[1]).toHaveAttribute(
+ expect(menuItems[1]).toHaveAttribute(
'href',
'https://github.com/freeCodeCamp/freeCodeCamp2'
);
@@ -75,9 +71,9 @@ describe('
', () => {
it('rendering the correct button when files is present', () => {
// @ts-ignore
- const { getByText } = render(
);
+ render(
);
- const button = getByText('buttons.show-code');
+ const button = screen.getByText('buttons.show-code');
expect(button).toBeInTheDocument();
});
});
diff --git a/client/src/components/search/searchBar/SearchBar.test.tsx b/client/src/components/search/searchBar/SearchBar.test.tsx
index 8363083af7..bbbed09661 100644
--- a/client/src/components/search/searchBar/SearchBar.test.tsx
+++ b/client/src/components/search/searchBar/SearchBar.test.tsx
@@ -5,10 +5,10 @@ import { SearchBar } from './search-bar';
describe('
', () => {
it('renders to the DOM', () => {
- const shallow = ShallowRenderer.createRenderer();
- shallow.render(
);
- const result = shallow.getRenderOutput();
- expect(result).toBeTruthy();
+ const utils = ShallowRenderer.createRenderer();
+ utils.render(
);
+ const view = utils.getRenderOutput();
+ expect(view).toBeTruthy();
});
/* Todo: When e2e testing is in place,
diff --git a/client/src/components/settings/Certification.test.js b/client/src/components/settings/Certification.test.js
index cdf10fd4e9..bc6ad4d0c8 100644
--- a/client/src/components/settings/Certification.test.js
+++ b/client/src/components/settings/Certification.test.js
@@ -1,5 +1,5 @@
import React from 'react';
-import { render } from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
import { Provider } from 'react-redux';
import { createStore } from '../../redux/createStore';
@@ -15,75 +15,64 @@ describe('
', () => {
// shallow rendering does not render children component
// form buttons are not included in shallow render
it('Should render show cert button for claimed legacy cert', () => {
- const { container } = renderWithRedux(
-
- );
+ renderWithRedux(
);
expect(
- container.querySelector(
- 'a[href="/certification/developmentuser/legacy-data-visualization"]'
- )
- ).toHaveTextContent('buttons.show-cert');
- });
-
- it('Should link show cert button to the claimed legacy cert', () => {
- const { container } = renderWithRedux(
-
+ screen.getByRole('link', {
+ name: 'buttons.show-cert'
+ })
+ ).toHaveAttribute(
+ 'href',
+ '/certification/developmentuser/legacy-data-visualization'
);
-
- expect(
- container.querySelector(
- 'a[href="/certification/developmentuser/legacy-data-visualization"]'
- )
- ).toBeInTheDocument();
});
// full forms with unclaimed certs should not shallow render show cert button
it('Should not render show cert button for unclaimed cert with completed projects', () => {
- const { container } = renderWithRedux(
-
- );
+ renderWithRedux(
);
- expect(
- container.querySelector(
- 'a[href="/certification/developmentuser/legacy-back-end"]'
- )
- ).not.toHaveTextContent('buttons.show-cert');
+ const allClaimedCerts = screen.getAllByRole('link', {
+ name: 'buttons.show-cert'
+ });
+
+ allClaimedCerts.forEach(cert => {
+ expect(cert).not.toHaveAttribute(
+ 'href',
+ '/certification/developmentuser/legacy-back-end'
+ );
+ });
});
// empty forms with unclaimed certs should not shallow render show cert button
it('Should not render show cert button for cert with no completed projects', () => {
- const { container } = renderWithRedux(
-
- );
+ renderWithRedux(
);
- expect(
- container.querySelector(
- 'a[href="/certification/developmentuser/legacy-front-end"]'
- )
- ).not.toHaveTextContent('buttons.show-cert');
+ const allClaimedCerts = screen.getAllByRole('link', {
+ name: 'buttons.show-cert'
+ });
+
+ allClaimedCerts.forEach(cert => {
+ expect(cert).not.toHaveAttribute(
+ 'href',
+ '/certification/developmentuser/legacy-front-end'
+ );
+ });
});
it('Render button when only solution is present', () => {
- const { container } = renderWithRedux(
-
- );
+ renderWithRedux(
);
expect(
- container.querySelector('#btn-for-5e46f802ac417301a38fb92b')
+ screen.getByRole('link', {
+ name: 'buttons.show-solution'
+ })
).toHaveAttribute('href', 'https://github.com/freeCodeCamp/freeCodeCamp');
});
it('Render button when both githubLink and solution is present', () => {
- const { container } = renderWithRedux(
-
- );
-
- const linkList = container.querySelector(
- '#dropdown-for-5e4f5c4b570f7e3a4949899f + ul'
- );
- const links = linkList.querySelectorAll('a');
+ renderWithRedux(
);
+ const links = screen.getAllByRole('menuitem');
expect(links[0]).toHaveAttribute(
'href',
'https://github.com/freeCodeCamp/freeCodeCamp1'
@@ -96,11 +85,9 @@ describe('
', () => {
});
it('rendering the correct button when files is present', () => {
- const { getByText } = renderWithRedux(
-
- );
+ renderWithRedux(
);
- const button = getByText('buttons.show-code');
+ const button = screen.getByText('buttons.show-code');
expect(button).toBeInTheDocument();
});
});
diff --git a/client/src/components/settings/Honesty.test.js b/client/src/components/settings/Honesty.test.js
index 6ae2884e4e..7cd60a56e7 100644
--- a/client/src/components/settings/Honesty.test.js
+++ b/client/src/components/settings/Honesty.test.js
@@ -13,16 +13,16 @@ describe('
', () => {
const componentToRender = (
);
- const component = renderer.render(componentToRender);
- expect(component).toMatchSnapshot('Honesty');
+ const view = renderer.render(componentToRender);
+ expect(view).toMatchSnapshot('Honesty');
});
test('
snapshot when isHonest is true', () => {
const componentToRender = (
);
- const component = renderer.render(componentToRender);
- expect(component).toMatchSnapshot('HonestyAccepted');
+ const view = renderer.render(componentToRender);
+ expect(view).toMatchSnapshot('HonestyAccepted');
});
test('should call updateIsHonest method on clicking agree button', () => {
@@ -30,6 +30,11 @@ describe('
', () => {
).root;
+ /**
+ * This rules had to be disabled because the new lint rules are throwing false positives here.
+ * They were interpreting react-test-renderer functions as @testing-library/react functions.
+ */
+ // eslint-disable-next-line testing-library/await-async-query
root.findByType(Button).props.onClick();
expect(updateIsHonestMock).toHaveBeenCalledWith({ isHonest: true });
});
diff --git a/client/src/templates/Challenges/components/__snapshots__/completion-modal-body.test.tsx.snap b/client/src/templates/Challenges/components/__snapshots__/completion-modal-body.test.tsx.snap
index 5e9fe99584..731152dc19 100644
--- a/client/src/templates/Challenges/components/__snapshots__/completion-modal-body.test.tsx.snap
+++ b/client/src/templates/Challenges/components/__snapshots__/completion-modal-body.test.tsx.snap
@@ -12,6 +12,7 @@ exports[`
matches snapshot 1`] = `
matches snapshot 1`] = `