This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it("shows error notification if error occurs", () => { | |
useFetch.mockReturnValue({ | |
loading: false, | |
data: [], | |
error: "Some error occured!", | |
}); | |
const { getByTestId } = render(<CountriesContainer />); | |
expect(getByTestId("error-message")).toBeInTheDocument(); | |
expect(getByTestId("error-message")).toHaveTextContent( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it("shows countries when data are fetched", () => { | |
useFetch.mockReturnValue({ | |
loading: false, | |
data: stubbedCountries, | |
error: null, | |
}); | |
const { getByTestId } = render(<CountriesContainer />); | |
expect(getByTestId("Slovakia-card")).toBeInTheDocument(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it("shows loading when data are being fetched", () => { | |
useFetch.mockReturnValue({ | |
loading: true, | |
data: [], | |
error: null, | |
}); | |
const { getByTestId } = render(<CountriesContainer />); | |
expect(getByTestId("loading-spinner")).toBeInTheDocument(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { render, act, fireEvent } from "@testing-library/react"; | |
import CountriesContainer from "./CountriesContainer"; | |
import { useFetch } from "../utils/customHooks"; | |
jest.mock("../utils/customHooks"); | |
const stubbedCountries = [ | |
{ | |
numericCode: 1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useRef, useReducer } from "react"; | |
import CountryCard from "../components/CountryCard/CountryCard"; | |
import AdvancedFilter from "../components/AdvancedFilter/AdvancedFilter"; | |
import { useFetch } from "../utils/customHooks"; | |
import { Spinner } from "../utils/Spinner"; | |
import "./CountriesContainer.css"; | |
const CountriesContainer = () => { | |
const componentIsMounted = useRef(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("AdvancedFilter component", () => { | |
// ... | |
it("triggers event handler on input change of name", () => { | |
const changedSearchValue = { ...stubbedSearchValue, name: "Slovakia" }; | |
const { getByTestId, rerender } = render( | |
<AdvancedFilter | |
searchValue={stubbedSearchValue} | |
handleChangeValue={mockChangeValue} | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { render, fireEvent, act } from "@testing-library/react"; | |
import AdvancedFilter from "./AdvancedFilter"; | |
describe("AdvancedFilter component", () => { | |
const mockChangeValue = jest.fn(); | |
const stubbedSearchValue = { | |
name: "", | |
capital: "", | |
population: "", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import "./CountryCard.css"; | |
const CountryCard = ({ country }) => ( | |
<div className="country-card" data-testid={`${country.name}-card`}> | |
<h3>{country.name}</h3> | |
<hr /> | |
<ul className="country-info-list"> | |
<li className="country-info-item"> | |
<h4>Capital:</h4> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import CountryCard from "./CountryCard"; | |
import { render } from "@testing-library/react"; | |
const stubbedCountry = { | |
name: "Slovakia", | |
population: 5000000, | |
capital: "Bratislava", | |
region: "Europe", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "your-project-name", | |
"version": "0.1.0", | |
"private": true, | |
"dependencies": { | |
"react": "^16.12.0", | |
"react-dom": "^16.12.0", | |
"react-scripts": "3.3.0" | |
}, | |
"devDependencies": { |