Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with React Native Web? #290

Open
vicky-carbon opened this issue Feb 15, 2023 · 5 comments
Open

Usage with React Native Web? #290

vicky-carbon opened this issue Feb 15, 2023 · 5 comments
Labels
examples feature request Request a new feature help wanted Extra attention is needed

Comments

@vicky-carbon
Copy link

vicky-carbon commented Feb 15, 2023

What is the framework/ technology you want to integrate Jest Preview to?

React Native Web.

Useful links

Styling

Do you want to add this example by your own?

I need help integrating jest-preview to my project that uses react-native-web and Next.js. I followed the example for Next.js with babel but the styles aren't working (RNW did not inject the CSS rules at runtime).

@nvh95 nvh95 added help wanted Extra attention is needed feature request Request a new feature labels Feb 16, 2023
@antoniel
Copy link

I've been interested in using Jest Preview with React Native for some time now, and I've been exploring different ways to make it work. I did try using react-native-web, but I ran into some issues related to the jsdom environment and the fact that the React Native version of the testing library expects the node environment. While this may not be an issue for you if you're using a Next.js app, jsdom could be a problem for developers who want to use Jest Preview exclusively with a React Native jsdom environment.

I've been working on a solution that involves transforming React Native JSX into HTML. This would enable developers to visualize their components in Jest Preview more easily and would eliminate the need for the jsdom environment altogether. I'm still working on some of the details of this solution, but I believe it could be a valuable addition to the project

@antoniel
Copy link

I have an idea for how this transformation could be used in practice. I envision that the react-native-to-html package (WIP) could be integrated into the Jest Preview interface as a replacement for the current implementation of the preview function in /src/preview.ts.

With this implementation, the debug function in Jest Preview would accept a parameter that replaces the use of document.documentElement.outerHTML. For example, in a React Native project, developers could use the toJSON function from react-test-renderer to generate a JSON representation of a component, and then pass that JSON to the debug function to generate the corresponding HTML output.

Here's an example of how this could work in practice:

import { render } from '@testing-library/react-native';
import { toHtml } from 'react-native-to-html';

const { toJSON } = render(...);
const html = toHtml(toJSON());
preview.debug(html);

@nvh95
Copy link
Owner

nvh95 commented Feb 20, 2023

Hi @vicky-carbon @antoniel. I am not familiar with react-native and react-native-web for now. So another maintainer @ntt261298 and I will explore it a little bit more and get back to you guys. In the meantime, if you guys have a repo which uses react-native and react-native-web for us to play with, it would save us a ton of time.

Thanks.

@antoniel
Copy link

Yo @nvh95, I'll be happy to help creating the repo. I should be able to have it set up by tomorrow

@antoniel
Copy link

@nvh95 take a look on https://github.com/antoniel/react-native-to-jest-preview/tree/main/examples/react-native

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples feature request Request a new feature help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants