Skip to content

Commit

Permalink
switch to react-testing-library
Browse files Browse the repository at this point in the history
  • Loading branch information
jonstieglitz committed Sep 15, 2021
1 parent 2eb8795 commit 6ebc092
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ const Spinner: React.FC = () => (
</div>
);

export default Spinner;
export default Spinner;
19 changes: 9 additions & 10 deletions src/components/layouts/ContentSection.test.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
/* eslint-env jest */
// import { configure, HTMLAttributes, shallow, ShallowWrapper } from 'enzyme';
import { render, RenderResult, screen } from '@testing-library/react';
import React from 'react';
import ContentSection from './ContentSection';
import Root from '../../root/Root'

describe('Selected state of temperature butttons', () => {
let actualContent: RenderResult
// let fahrenheitButton: ShallowWrapper<HTMLAttributes, any>
// let celciusButton: ShallowWrapper<HTMLAttributes, any>
let fahrenheitButton: HTMLElement
let celciusButton: HTMLElement

beforeEach(() => {
actualContent = render(
render(
<Root>
<ContentSection />
</Root>
);
// fahrenheitButton = actualContent.find('[data-id="F"]');
// celciusButton = actualContent.find('[data-id="C"]');
fahrenheitButton = screen.getByTestId('F');
celciusButton = screen.getByTestId('C');
});

it('renders App component', () => {
Expand All @@ -27,13 +26,13 @@ describe('Selected state of temperature butttons', () => {

it('is on Celcius at load', () => {
// assert
// expect(celciusButton).toHaveClass("section__temperature__button--selected");
// expect(fahrenheitButton).toHaveClass("section__temperature__button--unselected");
expect(celciusButton).toHaveClass("section__temperature__button--selected");
expect(fahrenheitButton).toHaveClass("section__temperature__button--unselected");
});

// it('switches to Fahrenheit if the F buton is clicked', () => {
// // act
// fahrenheitButton.simulate('click');
// act
// fahrenheitButton.simulate('click');

// // assert
// expect(fahrenheitButton).toHaveClass("section__temperature__button--selected");
Expand Down
4 changes: 2 additions & 2 deletions src/components/layouts/ContentSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ const ContentSection: React.FC = () => {
<section className="section">
<div className="section__temperature">
<button
data-id="C"
data-testid="C"
className={`section__temperature__button ${isCelsius ? "section__temperature__button--selected" : "section__temperature__button--unselected"}`}
onClick={getDegreeCelsius}
>
<sup>o</sup>C
</button>
<button
data-id="F"
data-testid="F"
className={`section__temperature__button ${!isCelsius ? "section__temperature__button--selected" : "section__temperature__button--unselected"}`}
onClick={getDegreeFahrenheit}
>
Expand Down

0 comments on commit 6ebc092

Please sign in to comment.