• 3 months ago
In Next.js, child components are essential for creating a well-structured, modular, and scalable application.

I prefer to test each component separately in my applications. For this purpose, In next.js I'm creating mocks to replace the child components during the testing. This video shows how I'm creating a mock for a child component.
Transcript
00:00I want to test my Next.js component using just my component contains even a child.
00:17In my test file I want to get this text.
00:30Let's run a test.
00:46The errors are due to my child component which uses multiple dependencies.
01:02I will create a separate test file for it.
01:08In this test I am not interested in child component.
01:16To solve this problem I will identify the location of my child component.
01:31And then I will create a mock in my test file for my child component.
01:47Now I will run again the test.
02:02And the test is passed.

Recommended