React native React Testing Library/Jest Dom-收到的值必须是HtmleElement或SVGElement

React native React Testing Library/Jest Dom-收到的值必须是HtmleElement或SVGElement,react-native,react-testing-library,react-native-testing-library,jest-dom,React Native,React Testing Library,React Native Testing Library,Jest Dom,我是单元测试新手,我正在尝试呈现一个组件来了解更多关于库的信息 编辑:我正试着跟着指南走 组件 <TouchableOpacity style={style} onPress={onPress} accessibilityRole="button"> <AppText style={textStyle}>{title.toUpperCase()}</A

我是单元测试新手,我正在尝试呈现一个组件来了解更多关于库的信息

编辑:我正试着跟着指南走

组件

<TouchableOpacity
            style={style}
            onPress={onPress}
            accessibilityRole="button">
            <AppText style={textStyle}>{title.toUpperCase()}</AppText>
        </TouchableOpacity> 
it("Has the correct title in the button", () => {
        const { getByText } = render(<AppButton title="Hello" />);
        expect(getByText("HELLO")).toBeInTheDocument();
    });

谢谢你调查这件事!关于我做错了什么有什么建议吗?

这是一个有效的解决方案,如果我通过testID访问它,它会起作用

it("Has the correct title in the button", () => {
        const { getByTestId } = render(<AppButton title="Hello" />);
        const eins = getByTestId("text");
        expect(eins.children[0]).toEqual("HELLO");
});
it(“按钮中有正确的标题”,()=>{
const{getByTestId}=render();
const eins=getByTestId(“文本”);
期望(eins.children[0]).toEqual(“你好”);
});

虽然理解为什么我不能用
getByText
获取值会很好,但至少它是有效的。:)

为了澄清,您在测试中使用的是
react测试库
还是
react native测试库
?嘿,我使用的是react native测试库:)如果您尝试使用
queryByText
而不是
getByText
,它是否有效?我使用了testID,并且它按照预期工作:)
it("Has the correct title in the button", () => {
        const { getByTestId } = render(<AppButton title="Hello" />);
        const eins = getByTestId("text");
        expect(eins.children[0]).toEqual("HELLO");
});