Skip to content

Commit

Permalink
M0nica#66 add tests for statusCodeCard with usage of @testing-library…
Browse files Browse the repository at this point in the history
…/react library
  • Loading branch information
eLeontev committed Oct 26, 2020
1 parent 1872a94 commit 6134793
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions components/statusCodeCard.test.tsx
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} ↗`);
});
});

0 comments on commit 6134793

Please sign in to comment.