26 lines
900 B
React
26 lines
900 B
React
|
import { describe, it, expect } from "vitest";
|
|||
|
import { searchAndResizeImage } from "../../src/api/image-request"
|
|||
|
|
|||
|
describe("Image request API", () => {
|
|||
|
|
|||
|
|
|||
|
it("return a string", async () => {
|
|||
|
let query = 'cat';
|
|||
|
let imageUrl = await searchAndResizeImage(query);
|
|||
|
let isString = typeof imageUrl == 'string'
|
|||
|
expect(isString).toBe(true);
|
|||
|
});
|
|||
|
|
|||
|
it("returns a valid image URL when results are found", async () => {
|
|||
|
let query = 'cat';
|
|||
|
let imageUrl = await searchAndResizeImage(query);
|
|||
|
expect(imageUrl).toMatch(/^https?:\/\/.*\.(?:png|jpg|jpeg|gif|webp)$/i);
|
|||
|
});
|
|||
|
|
|||
|
it("returns an empty string when no image is found", async () => {
|
|||
|
const query = '[][][][][][][][][][][][][][]'; //cette requ<71>te ne renvoie aucune image
|
|||
|
const imageUrl = await searchAndResizeImage(query);
|
|||
|
expect(imageUrl).toEqual('');
|
|||
|
});
|
|||
|
});
|