Giter VIP home page Giter VIP logo

Comments (3)

Charly6596 avatar Charly6596 commented on August 22, 2024 1

Hey there, I'm currently using @shopify/restyle with @testing-library/react-native, all I had to do is to create a file (component-test-utils.tsx in my case) and export everything from @testing-library/react-native overwritting the render export with a function that takes the same arguments as render but uses a predefined wrapper (hence the wrapper is passed as an option)
You can add any other provider your tests need to the Providers function component. In your tests, instead of importing from @testing-library/react-native, you would have to import from your own file instead

component-test-utils.tsx:

import * as React from "react";
import { render } from "@testing-library/react-native";
import { ThemeProvider } from "@shopify/restyle";
import theme from "../Theme";

type ProvidersProps = {
  children?: React.ReactNode;
};

const Providers = ({ children }: ProvidersProps) => {
  return <ThemeProvider theme={theme}>{children}</ThemeProvider>;
};

const customRender: typeof render = (component, options) => {
  return render(component, { wrapper: Providers, ...options });
};

export * from "@testing-library/react-native";
export { customRender as render };

Box.spec.tsx:

import * as React from "react";
import Box from "../Box";
import { render } from "./component-test-utils";

describe("Box component", () => {
  it("renders", () => {
    const testID = "testID";
    const { getByTestId } = render(<Box testID={testID} />);
    expect(getByTestId(testID)).toBeTruthy();
  });
});

It works for me, hope it helps. I don't know if this would solve your problem tho, since I didn't face it

from restyle.

jdmg94 avatar jdmg94 commented on August 22, 2024

you might want to look into @testing-library/react-native as they have announced they're merging:

https://callstack.com/blog/merge-of-react-native-testing-libraries/

from restyle.

drmas avatar drmas commented on August 22, 2024

@thozh I'll close this issue for now, let me know if @Charly6596 didn't work for you and then we can re-open it back

from restyle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.