๐Ÿ‘พ Exercise: Props
by Tomas Trescakยท React

Root Folder
Not Attempted
NameProgress
Introduction
Not Read
๐Ÿฐ Player
Not Read
Setup
Not Attempted
NameProgress
Software Installation
Not Read
Project Setup
Not Read
Running and Testing
Not Read
React and ReactDOM
Not Read
๐Ÿ’ก Assignment 1: Welcome Message
Not Attempted
Submissions
Not Read
JSX and Components
Props
๐Ÿ‘พ Exercise: Props
Not Attempted
CSS Styles
useState and Hooks
๐Ÿ‘พ Exercise: useState
Not Attempted
Conditional Rendering
Lists
๐Ÿ‘พ Exercise: Lists
Not Attempted
Forms and Events
๐Ÿ‘พ Exercise: Forms
Not Attempted
๐Ÿ’ก Assignment 2: Front End
Not Attempted
Advanced React
Not Attempted
NameProgress
Pure Components - memo
Not Read
Lifecycle - useEffect
Not Read
Expensive? - useMemo
Not Read
DOM Interactions - useRef
Not Read
forwardRef
Not Read
useImperativeHandle
Not Read
๐Ÿ‘พ useImperativeHandle
Not Attempted
Context
Not Read
useCallback
Not Read
useId
Not Read
useReducer
Not Read
Infrastructure
Not Attempted
NameProgress
Database
Not Read
NextAuth and Github Authentication
Not Read
Prisma and ORM
Not Read
Project Setup
Not Read
Project Authentication
Not Read
APIs
Not Attempted
NameProgress
APIs
Not Read
APIs - Slides
Not Attempted
Rest APIs
Not Read
Rest APIs - Express.js
Not Read
ReastAPIs - Next.js
Not Read
Securing APIs
Not Read
Securing APIs - NextAuth
Not Read
tRPC
Not Attempted
NameProgress
tRPC
Not Read
tRPC - Routers
Not Read
tRPC - Server Rendering
Not Read
tRPC - Client Rendering
Not Read
Persisting Data
Not Read
Assignment 3: APIs
Not Read
0 / 1070 XP

Lecture Transcript
If you prefer text to video, check out the transcript of the presentation above

Let's practice!

In this exercise, you will create a reusable Greeting component. Initially, you will see these four failing tests.

Your goal is to make them all pass and render the following text on the screen.

These are the ways to use the Greeting component, with age being an optional prop.

Start with correctly defining the type of your props, providing names and types of the three component props.

Then, define your component. Make sure you specify that the default value of age prop is 44.

If you are not sure what the Greeting component has to show, check out the test file. There, you find a new type of test that uses a helper function "it" from the DOM library. This function accepts three parameters.

The first parameter is the name of the test, describing what the test expects.

The second parameter is the component that we test. This test helper temporarily renders the component in your browser and executes the test. After the component is tested, the component will be removed from the DOM. So, you don't need to render the expected texts in your main app, as the component is tested in isolation.

The last parameter is the implementation of the test function, where we test if the component renders everything that we expect.

In this exercise, I would like you to create a reusable Greeting component.

Initially, you will see four failing tests:

Your goal is to make them all pass:

 

๐ŸŽฏ GOALS

To do so, you need to modify the component Greeting as per instructions in your test. Overall these ar the goals:

  1. Show a greeting in the form Hello Tomas, male, age 50
  2. Age is an optional prop, the default value is 44

โ„น๏ธ HELP

If unclear, please check out the index.test.tsx file. There, you find a new type of test that uses our helper function dom.it(name, component, test), which accepts three parameters:

  1. name is the name of the test
  2. component is the component that we render for the purpose of this test
  3. test is the implmentation of the test function

This test helper temporarily renders the component into DOM and executes the test. Afterward, this component will be removed from the DOM.

// Example 
describe ("Test Greeting Component", function() {
  dom.it ("Renders Tomas", 
    <Greeting name="Tomas" age={50} gender="male" />, 
    async function() {
      assert.exists(await dom.findByText("Hello Tomas, male, age 50"));
    }
  )
})

๐Ÿค‘ BONUS

  1. Correctly define the type of props of the component Greeting
  2. Make sure there are no errors 

Discussion

0 comments
Loading editor ...
Remember to be polite and report any undesirable behaviour

Category

Empty

Labels

Discussion has no labels

1 participant

user avatar

Priority

Notifications

You're not receiving notifications from this thread.
Loading...
Ready ...
Course Outline