无法在具有样式的Text元素上找到标签或文本

时间:2020-06-12 10:20:51

标签: react-native detox

我已经在Detos文档关闭的问题中搜索了以下错误,但找不到它,所以希望我不要错过文档中明显的内容,但这是我的问题:

配置:

  • ios:13.1
  • 排毒:“ ^ 16.7.1”
  • 开玩笑:“ ^ 26.0.1”
  • 本机:“ 0.62.2”

我的React Native代码:

// App.js

<View style={styles.container} testID='my-view'>
    <Text testID='text'>Hello!</Text>
    <Text style={styles.title} testID='text-test'>Hello!</Text>
</View>

这是我的测试:

// test.spec.js

describe('User journey', () => {
  beforeEach(async () => {
    await device.reloadReactNative();
  });
  it('should render screen', async () => {
    await expect(element(by.id('my-view'))).toExist(); // TRUE
    await expect(element(by.id('text'))).toHaveText('Hello!'); // TRUE
    await expect(element(by.id('text-test'))).toHaveText('Hello!'); // FALSE
  });
});

错误是:

> Cannot find UI Element.
>     Exception with Assertion: {
>       "Assertion Criteria":  "assertWithMatcher:isNotNil",
>       "Element Matcher":  "((!(kindOfClass('RCTScrollView')) && ((((kindOfClass('UILabel') || kindOfClass('UITextField') ||
> kindOfClass('UITextView')) && hasText('Coucou')) ||
> (kindOfClass('RCTTextView') && an object with accessibilityLabel
> "Coucou")) && !(kindOfClass('UIAccessibilityTextFieldElement')))) ||
> (((kindOfClass('UIView') ||
> respondsToSelector(accessibilityContainer)) &&
> parentThatMatches(kindOfClass('RCTScrollView'))) &&
> ((kindOfClass('UIView') || respondsToSelector(accessibilityContainer))
> && parentThatMatches(((((kindOfClass('UILabel') ||
> kindOfClass('UITextField') || kindOfClass('UITextView')) &&
> hasText('Coucou')) || (kindOfClass('RCTTextView') && an object with
> accessibilityLabel "Coucou")) &&
> !(kindOfClass('UIAccessibilityTextFieldElement')))))))",
>       "Recovery Suggestion":  "Check if the element exists in the UI hierarchy printed below. If it exists, adjust the matcher so that it
> accurately matches element."
>     } [...]

我尝试过:

await expect(element(by.id('text-test'))).toHaveText('Hello!');
await expect(element(by.id('text-test'))).toHaveLabel('Hello!');
await expect(element(by.label('Hello!'))).toExist();
await expect(element(by.text('Hello!'))).toExist();

它们都可以在“ testID ='text'”上正常工作,但是在“ testID ='text-test'”上则失败。如果我删除style = {styles.title},则可以。

我是否错过了有关样式和测试的内容?

0 个答案:

没有答案