Skip to content

Commit

Permalink
update exercise5
Browse files Browse the repository at this point in the history
  • Loading branch information
talgat-ruby committed Nov 8, 2023
1 parent b43165b commit eeb4cd9
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions exercise5/problem7/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,30 @@ describe("exercise5 - problem7", () => {
image: pokemon.sprites.front_default,
}));

vi.spyOn(global, "fetch").mockImplementationOnce(() => {
const blob = new Blob([JSON.stringify(pokemons, null, 2)], {
type: "application/json",
});
vi.spyOn(global, "fetch").mockImplementationOnce(async (url) => {
let path = "";

if (url instanceof URL) {
path = url.href;
} else if (url instanceof Request) {
path = url.url;
} else if (typeof url === "string") {
path = url;
}

let blob = new Blob();

if (path.includes(pokemons[0].name)) {
blob = new Blob([JSON.stringify(pokemons[0], null, 2)], {
type: "application/json",
});
}

if (path.includes(pokemons[1].name)) {
blob = new Blob([JSON.stringify(pokemons[1], null, 2)], {
type: "application/json",
});
}

const response = new Response(blob, {
status: 200,
Expand Down

0 comments on commit eeb4cd9

Please sign in to comment.