From 8d25159d0cc3799ba8a1c12955e293d722639163 Mon Sep 17 00:00:00 2001 From: Branden Jones Date: Wed, 24 Apr 2024 13:57:50 -0400 Subject: [PATCH] first unit test --- src/App.js | 8 +++++++- src/components/RestaurantList.js | 11 +++++++++++ src/components/RestaurantList.spec.js | 12 ++++++++++++ src/components/RestaurantScreen.js | 13 +++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/components/RestaurantList.js create mode 100644 src/components/RestaurantList.spec.js create mode 100644 src/components/RestaurantScreen.js diff --git a/src/App.js b/src/App.js index bd268fd..d3f1461 100644 --- a/src/App.js +++ b/src/App.js @@ -1,4 +1,10 @@ +import RestaurantScreen from './components/RestaurantScreen'; export default function App() { - return
Hello, World
+ return + ( +
+ +
+ ) } \ No newline at end of file diff --git a/src/components/RestaurantList.js b/src/components/RestaurantList.js new file mode 100644 index 0000000..7aa954f --- /dev/null +++ b/src/components/RestaurantList.js @@ -0,0 +1,11 @@ +import { useEffect } from "react"; + +export default function RestaurantList({ loadRestaurants }) +{ + useEffect(() => { loadRestaurants(); }, [loadRestaurants]); + return + ( + +
RestaurantList
+ ) +} \ No newline at end of file diff --git a/src/components/RestaurantList.spec.js b/src/components/RestaurantList.spec.js new file mode 100644 index 0000000..c3c29df --- /dev/null +++ b/src/components/RestaurantList.spec.js @@ -0,0 +1,12 @@ +import { render } from '@testing-library/react'; +import RestaurantList from './RestaurantList'; + +describe('RestaurantList', () => +{ + it('loads restaurants on first render', () => + { + const loadRestaurants = jest.fn().mockName('loadRestaurnats'); + render(); + expect(loadRestaurants).toHaveBeenCalled(); + }); +}); \ No newline at end of file diff --git a/src/components/RestaurantScreen.js b/src/components/RestaurantScreen.js new file mode 100644 index 0000000..bba4e94 --- /dev/null +++ b/src/components/RestaurantScreen.js @@ -0,0 +1,13 @@ +import RestaurantList from "./RestaurantList"; + +export default function RestaurantScreen() +{ + return + ( +
+

Restaurants

+ +
+ + ) +} \ No newline at end of file