Skip to content

Commit

Permalink
Fix Format test problems
Browse files Browse the repository at this point in the history
  • Loading branch information
bigotes0invisibles committed Nov 3, 2023
1 parent ffcb2f8 commit 02ab4d7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 59 deletions.
54 changes: 16 additions & 38 deletions src/components/CharacterList/CharaterList.test.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,28 @@
import { ThemeProvider } from "styled-components";
import mainTheme from "../../styles/mainTheme";
import { render, screen, waitFor } from "@testing-library/react";
import { render, screen } from "@testing-library/react";
import CharactersWrapper from "../../features/characters/store/CharactersWrapper";
import { MemoryRouter } from "react-router-dom";
import UiContextWrapper from "../../features/Ui/store/UiContextWrapper";
import CharacterList from "./CharacterList";
import CharactersContext from "../../features/characters/store/CharactersContext";

const characters = [
{
id: 1,
name: "Mario",
availability: "Starter",
appears: ["SSB", "Melee", "Brawl", "SSB4"],
attack: "Mario Finale",
smashtype: "Directional",
imageUrl:
"https://raw.githubusercontent.com/HugoVS26/ConejosVoladores-202309-bcn-API/main/images/1.webp",
series: "Mario",
},
{
id: 2,
name: "Donkey Kong",
availability: "Starter",
appears: ["SSB", "Melee", "Brawl", "SSB4"],
attack: "Konga Beat",
smashtype: "Focused",
imageUrl:
"https://raw.githubusercontent.com/HugoVS26/ConejosVoladores-202309-bcn-API/main/images/2.webp",
series: "Donkey Kong",
},
];
import mockCharacters from "../../mocks/mockData";
import { characterApiToCharacter } from "../../data/apiSmash";

describe("Given the component CharacterList", () => {
describe("When CharacterList is initialize", () => {
test("It should have strated the list", async () => {
test("It should have strated the list", () => {
const ulTagName = "list";
const liTagName = "listitem";

await waitFor(() =>
render(
<UiContextWrapper>
<CharactersWrapper>
<ThemeProvider theme={mainTheme}>
<CharacterList />
</ThemeProvider>
</CharactersWrapper>
</UiContextWrapper>,
),
render(
<UiContextWrapper>
<CharactersWrapper>
<ThemeProvider theme={mainTheme}>
<CharacterList />
</ThemeProvider>
</CharactersWrapper>
</UiContextWrapper>,
);

const elementList = screen.queryByRole(ulTagName);
Expand All @@ -63,6 +38,9 @@ describe("Given the component CharacterList", () => {
const mario = "Mario";
const donkeyKong = "Donkey Kong";
const loadCharacters = () => {};
const characters = mockCharacters.map((characterApi) =>
characterApiToCharacter(characterApi),
);

render(
<ThemeProvider theme={mainTheme}>
Expand All @@ -77,10 +55,10 @@ describe("Given the component CharacterList", () => {
const marioElement = screen.getByRole("heading", {
name: mario,
});

const donkeyKongElement = screen.getByRole("heading", {
name: donkeyKong,
});

expect(marioElement).toBeInTheDocument();
expect(donkeyKongElement).toBeInTheDocument();
});
Expand Down
39 changes: 18 additions & 21 deletions src/hooks/useCharactersApi.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,26 @@ import UiContextWrapper from "../features/Ui/store/UiContextWrapper";

describe("Given a getResponseCheck custom hook", () => {
describe("When it fetches the url https://smash-characters-api.onrender.com/characters", () => {
test(
"Then it should return an array of Characters",
async () => {
const apiCharacters = mockCharacters;
test("Then it should return an array of Characters", async () => {
const apiCharacters = mockCharacters;

const expectedCharacters = apiCharacters.map((characterApi) =>
characterApiToCharacter(characterApi),
);
const {
result: {
current: { loadCharactersApi },
},
} = renderHook(() => useCharactersApi(), {
wrapper: ({ children }) => (
<UiContextWrapper>{children}</UiContextWrapper>
),
});
const expectedCharacters = apiCharacters.map((characterApi) =>
characterApiToCharacter(characterApi),
);

const currentCharacters = await loadCharactersApi();
const {
result: {
current: { loadCharactersApi },
},
} = renderHook(() => useCharactersApi(), {
wrapper: ({ children }) => (
<UiContextWrapper>{children}</UiContextWrapper>
),
});

expect(currentCharacters).toStrictEqual(expectedCharacters);
},
{},
);
const currentCharacters = await loadCharactersApi();

expect(currentCharacters).toStrictEqual(expectedCharacters);
});
});
});

0 comments on commit 02ab4d7

Please sign in to comment.