Я пытаюсь проверить текст в кнопках заголовка компонента в навигаторе стека.Но у меня возникают проблемы с отображением навигатора в моих тестах.Я использую react-native-testing-libary
, но я предполагаю, что Enzyme будет работать примерно так же.
const Wrapper = props => (
<Fragment>
<SubscriptionProductDetailScreen
product={product}
testID={"SUBSCRIPTION_DETAIL_SCREEN"}
{...props}
/>
</Fragment>
);
describe('cart button, nav container', () => {
const Navigator = createStackNavigator({ Wrapper })
const navComponent = render(<Navigator navigation={{}} />)
it('says "cart"', () => {
expect(navComponent.getByText('Cart')).toBeDefined();
});
});
Я получаю две ошибки.Этот находится в верхней части вывода:
console.error node_modules/react-test-renderer/cjs/react-test-renderer.development.js:9215
The above error occurred in the <Navigator> component:
in Navigator (created by KeyboardAwareNavigator)
in KeyboardAwareNavigator
Consider adding an error boundary to your tree to customize error handling behavior.
Мой компонент использует KeyboardAvoidingView
, но не KeyboardAwareNavigator
.
Но тест на самом деле тоже не запускается:
● cart button, nav container › encountered a declaration exception
TypeError: Cannot read property 'routes' of undefined
at getDerivedStateFromProps (node_modules/@react-navigation/core/lib/commonjs/navigators/createNavigator.js:14:59)
at applyDerivedStateFromProps (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:3232:22)
at mountClassInstance (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:3605:5)
at updateClassComponent (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6786:5)
at beginWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7742:16)
at performUnitOfWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11413:12)
at workLoop (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11445:24)
at renderRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11528:7)
at performWorkOnRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12416:7)
at performWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12328:7)
Test Suites: 1 failed, 1 total
Как мне работать с react-native-navigation
в тестах таким образом?