server-components-demo icon indicating copy to clipboard operation
server-components-demo copied to clipboard

Is jest still sufficient to write unit tests for server components ?

Open waqasnoor opened this issue 4 years ago • 5 comments

So i was wondering if we can write unit tests for server side components using just ? since the the return data from server side components when return from server is some complex Object. Maybe we can add few unit tests in this demo project to showcase the uses.

waqasnoor avatar Dec 22 '20 18:12 waqasnoor

That complex object is the implementation details of the server component, which IMO should not be tested in the unit tests. I think We can test the server components just like the normal functional component, we can assert if some child component is getting rendered or not, and with what props the child components are getting rendered.

ashish-r avatar Dec 23 '20 14:12 ashish-r

Any way to test async components?

avin-kavish avatar Sep 12 '23 12:09 avin-kavish

yes

sibelius avatar Sep 12 '23 13:09 sibelius

care to elaborate?

avin-kavish avatar Sep 12 '23 13:09 avin-kavish

You can use jest multi projects to have both configs for client and server

like this https://github.com/sibelius/next-jest-multiproject/blob/main/jest.config.js

server components can run in both

sibelius avatar Sep 12 '23 13:09 sibelius