Skip to content

Instantly share code, notes, and snippets.

import React from "react";
// Can not really write good unit tests
// Every test should start with a mock of the API call to fetch the `book`
export default function BookDetail() {
const [isDeleteClicked, setDeleteClicked] = React.useState(false);
const { state: book, fetchBook, deleteBook } = React.useContext(BookContext);
const bookUrl = utils.buildBookUrlFromUri();
React.useEffect(() => {
import React from "react";
export default function SmartBookDetail() {
const [isDeleteClicked, setDeleteClicked] = React.useState(false);
const { state: book, fetchBook, deleteBook } = React.useContext(BookContext);
const bookUrl = utils.buildBookUrlFromUri();
React.useEffect(() => {
fetchBook(bookUrl);
}, []);
import React from "react";
// Same level of complexity for integration tests
export default function SetupBookDetail() {
const { state: book, fetchBook, deleteBook } = React.useContext(BookContext);
const bookUrl = utils.buildBookUrlFromUri();
React.useEffect(() => {
fetchBook(bookUrl);
}, []);