-
Notifications
You must be signed in to change notification settings - Fork 277
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
Hi there,
I switched over from Enzyme for my current RN project and I'm wondering how to handle a specific assertion.
Say I have a component like this:
const MyComponent = ({ value }) => {
return <Text testID="text">Value is {value}</Text>;
}
I now want to test that the component renders the value in the Text node:
const renderer = render(<MyComponent value="xyz" />);
const text = renderer.getByTestId("text");
expect(text.props.children).toBe("Value is xyz");
However, the test fails: Expected: "Value is xyz", Received: ["Value is ", "xyz"]
In Enzyme there is a .text() method on the node which flatly returns the text contained in the child. Is there a way to do this smoothly in react-native-testing-library?
Of course I could change the component to use string templates or reduce the props.children
in the test method to a string myself, just wondering if there is a better way.
raquelhortab and kopax-polyconseiljuniordeleon013
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested