React Testing Library Tutorial #9 - Describe Block
Skills:
JavaScript Fundamentals90%
Key Takeaways
Utilizes describe block for organizing tests with React Testing Library
Full Transcript
in this video we are going to cover a better way of structuring our tests now if we go back to this diagram here i illustrated that typically we have a test block and then within this test block we're going to have the content needed to execute our test and that is what we have been doing thus far here we have our test block and then we have the content to execute our test within the callback but now we have so many tests and we should have a way of grouping and organizing these tests and we can actually do that through describe blocks we can use describe blocks to group common tests for instance all these tests test the to do footer so we can have a describe block that groups all of these tests inside of that describe block then we can describe that these tests test the to-do footer so at the end of the day it might look something like this we are going to have a describe block and then we can group common tests within that describe block now also we could do something like this so we can have a describe block and we can have common tests within it but then we can also have a child describe block to even more separate tests out within the parent describe blocks over here we have these common tests and then these common tests but they're separated through this described block now we're not going to be doing this inside of this crash course but at the end of the day when you have more complicated tests in your application you can think of this as a way of separating things out but in this lecture we are just going to be using this approach so let's go ahead and let's use utilize the describe blocks now before i do that let's just comment out all of the unnecessary tests so over here we have the first test and then over here we have the second test i think these are the only two valid tests i mean all the tests are valid but the other ones were just a way of learning about assertions so i'll just comment these tests out this first test test if if things work as expected and then the second test tests if the text is plural or the text is singular if you pass one so let's just go ahead and let's save that and we should see three passing tests now what we can do is have a describe block and the describe block is going to be very similar we're going to have the first parameter is going to be a string that describes this block i'm just going to say to do footer because this is just testing the to-do footer and then in here we're going to have a callback and now what we're going to do is we're going to copy all this if i can copy it all right let me just zoom out a little bit here i'm going to copy this i'm really having a hard time here there we go i'm going to cut it out and just paste it inside of the describe block and if i save this you can see that everything passes all right cool and this is a typical convention and this is how most tests are going to be organized now notes you can always put another describe a block in here maybe saying that this is testing functionality one of this components and you can have maybe this test in here and then over here we can have another describe block and this is saying hello testing functionality 2 functionality 2 and then over here we can have another describe block so we can just cut this out paste it in here and this is completely valid again this is just a better way of reorganizing our organizing our components and our tests so let's just go ahead and let's just get rid of this describe block we don't need to actually let me just control z out of it because i don't want to have these children describe blocks let's just do there we go that should be fine and now let's just do the same thing for our other uh test file our header test file and we really have just one test here but let's just put it in a describe block anyways so we'll say here header and we'll just have a call back we'll cut this out paste it in done all right very short lecture on the best practices of organizing your tests
Original Description
Check out Laith's YouTube channel for more tutorials:
https://www.youtube.com/channel/UCyLNhHSiEVkVwPSFKxJAfSA
🐱💻 Access the course files on GitHub:
https://github.com/harblaith7/React-Testing-Library-Net-Ninja
🐱👤 Get access to extra premium courses on Net Ninja Pro:
https://netninja.dev
🐱💻 Full React Course:
https://www.youtube.com/watch?v=j942wKiXFu8&list=PL4cUxeGkcC9gZD-Tvwfod2gaISzfRiP9d
🐱💻 Social Links:
Facebook - https://www.facebook.com/thenetninjauk
Twitter - https://twitter.com/thenetninjauk
Instagram - https://www.instagram.com/thenetninja/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Net Ninja · Net Ninja · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
More on: JavaScript Fundamentals
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
X now offers an MCP server to make its platform easier for AI tools to use
TechCrunch AI
n8n Automation Repurpose Video Content: The 2025 Production Guide
Dev.to AI
You’re Still Paying $200/Month for AI Tools You Could Replace With a Free Local Setup Tonight
Medium · Data Science
Top 10 AI Tools Every College Student Should Know in 2026
Medium · AI
🎓
Tutor Explanation
DeepCamp AI