Skip to content

Commit c1e97d1

Browse files
committed
add test fo renderlist book
1 parent 8c98315 commit c1e97d1

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/components/Book/Book.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const Book = ({
2828
/>
2929
</a>
3030
<div>
31-
<a href="/#" target="_blank" className="book-link">
31+
<a href="/#" target="_blank" className="book-link" data-testid="title-book">
3232
{book.title}
3333
</a>
3434
<p className="book-authors">by {book.author}</p>

src/components/Book/__test__/Book.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { render } from '@testing-library/react';
2+
import { IBook } from '../../../interface/IBook';
23
import Book from '../Book';
34

45
describe("Book list", () => {
@@ -7,4 +8,29 @@ describe("Book list", () => {
78
const {getByText} = render(<Book listBook={[]} category={"Fiction"}/>)
89
expect(getByText(/No book/i)).toBeInTheDocument();
910
})
11+
12+
test('should render list of books', () => {
13+
const fakeBooks: IBook[] = [
14+
{
15+
author: "Clive Cussler and Justin Scott",
16+
contributor: "by Clive Cussler and Justin Scott",
17+
description: "In the ninth book in this series, set in 1906, the New York detective Isaac Bell contends with a crime boss passing as a respectable businessman and a tycoon’s plot against President Theodore Roosevelt.",
18+
primary_isbn13: "9780698406421",
19+
primary_isbn10: "0698406427",
20+
publisher: "Putnam",
21+
rank: 1,
22+
book_image: "https://storage.googleapis.com/du-prd/books/images/9781501110375.jpg",
23+
title: "THE GANGSTER",
24+
weeks_on_list: "34"
25+
}
26+
];
27+
28+
const {getAllByTestId} = render(<Book listBook={fakeBooks} category={"Fiction"}/>);
29+
const titleBook = getAllByTestId('title-book').map(title => title.textContent);
30+
const fakeTitleBook = fakeBooks.map(t => t.title);
31+
32+
expect(titleBook).toEqual(fakeTitleBook);
33+
});
34+
35+
1036
});

0 commit comments

Comments
 (0)