小编Ped*_*ges的帖子

NativeBase 内容未使用react-native-testing-library 在 Jest 中呈现

我有一些带有本机基础代码的react-native/expo,可以在手机或模拟器上正常运行。我尝试使用jestreact-native-testing-library为其创建一个测试。这样做时,无论里面有什么from native-base未渲染且无法在测试中找到。

有没有人经历过这个并且知道解决方案,以便在测试期间呈现 Content 的子项?

下面是一个示例代码来说明我的意思。非常感谢你的帮助。

import { render } from 'react-native-testing-library';
import {
  Content, Container, Text
} from 'native-base';


class App extends React.Component {

  render() {
    return (
      <Container>
        <Content>
          <Text testID="textId">Hello</Text>
        </Content>
      </Container>
    );
  }
}

describe('Testing Content', () => {
  const { queryByTestId } = render(<App />)
  it('renders text inside content', () => {
    expect(queryByTestId('textId')).not.toBeNull()
  });

})
Run Code Online (Sandbox Code Playgroud)

软件包的版本是:

"expo": "^32.0.0",
"react": "16.5.0",
"native-base": "^2.12.1",
"jest-expo": "^32.0.0",
"react-native-testing-library": "^1.7.0"
Run Code Online (Sandbox Code Playgroud)

jestjs react-native native-base expo react-testing-library

4
推荐指数
1
解决办法
3408
查看次数