OpenBCca / openbc-web

https://openbcca.github.io/openbc-web/
1 stars 2 forks source link

UT for app/layout.tsx and app/page.tsx #70

Closed Unknown-0perator closed 7 months ago

Unknown-0perator commented 8 months ago

I got a warning in terminal, couldn't able to solve it console.error Warning: validateDOMNesting(...): cannot appear as a child of

. at html at children (D:\OPENBC\openbc-web\src\app\layout.tsx:9:38)

  21 | describe('RootLayout', () => {
  22 |   it('renders without crashing', () => {
> 23 |     render(<RootLayout />);
     |           ^
  24 |   });
  25 |
  26 |   it('renders Header and Footer components', () => {
nam-m commented 8 months ago

It's because RootLayout contains html tag, which is the whole page. You probably won't need to test render the whole page

nam-m commented 8 months ago
Unknown-0perator commented 8 months ago

Thanks, @nam-m. Most people don't recommend Unit Testing (UT) for the main layout. However, rendering is necessary for testing {children}. I couldn't find a better solution, so we can either ignore the warning or remove UT for the layout.

nam-m commented 8 months ago

Thanks, @nam-m. Most people don't recommend Unit Testing (UT) for the main layout. However, rendering is necessary for testing {children}. I couldn't find a better solution, so we can either ignore the warning or remove UT for the layout.

Maybe we don't need unit test for the layout then. Since Next.js builds the page using html and body automatically, we can presume this will always work

SamHuo213 commented 7 months ago

Thanks, @nam-m. Most people don't recommend Unit Testing (UT) for the main layout. However, rendering is necessary for testing {children}. I couldn't find a better solution, so we can either ignore the warning or remove UT for the layout.

Maybe we don't need unit test for the layout then. Since Next.js builds the page using html and body automatically, we can presume this will always work

This makes sense to me.