forked from M0nica/httriri
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
M0nica#66 add tests for statusCodeCard with usage of @testing-library…
…/react library
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
|
||
import StatusCodeCard from "./statusCodeCard"; | ||
|
||
describe("StatusCodeCard", () => { | ||
let container: any; | ||
|
||
const code = "code"; | ||
const title = "title"; | ||
const description = "description"; | ||
|
||
beforeEach(() => { | ||
container = render( | ||
<StatusCodeCard | ||
code={code} | ||
title={title} | ||
description={description} | ||
/> | ||
).container; | ||
}); | ||
|
||
it("should render image with link to passed code gif and description as the image alternative", () => { | ||
const [img]: any = container.getElementsByTagName("img"); | ||
|
||
expect(img.alt).toBe(description); | ||
expect(img.src).toContain(`/images/${code}.gif`); | ||
}); | ||
|
||
it("should render link tag with link to statuses come with passed code and description contains code and tittle", () => { | ||
const [link]: any = container.getElementsByTagName("a"); | ||
|
||
expect(link.href).toBe(`https://httpstatuses.com/${code}`); | ||
expect(link.text).toBe(`${code}: ${title} ↗`); | ||
}); | ||
}); |