Jest: Моментальные снимки React Native завершаются ошибкой «TypeError: невозможно прочитать свойство '_tag' of undefined» для компонентов, содержащих<textinput/>

Созданный на 6 авг. 2016  ·  3Комментарии  ·  Источник: facebook/jest

Воспроизвести:

  1. Измените https://github.com/facebook/jest/blob/master/examples/react-native/Intro.js, чтобы добавить <TextInput /> в render ()
  2. тест npm

Результат:

FAIL tests /Intro-test.js (0.459s)
● Вступление ›отображается правильно.

  • TypeError: невозможно прочитать свойство _tag из undefined
    в ReactNativeBaseComponent.Mixin.mountComponent (node_modules / react / lib / ReactNativeBaseComponent.js: 179: 45)
    в Object.ReactReconciler.mountComponent (node_modules / react / lib / ReactReconciler.js: 47: 35)
    в ReactCompositeComponentMixin.performInitialMount (node_modules / react / lib / ReactCompositeComponent.js: 397: 34)
    в ReactCompositeComponentMixin.mountComponent (node_modules / react / lib / ReactCompositeComponent.js: 262: 21)
    в Object.ReactReconciler.mountComponent (node_modules / react / lib / ReactReconciler.js: 47: 35)
    в ReactCompositeComponentMixin.performInitialMount (node_modules / react / lib / ReactCompositeComponent.js: 397: 34)
    в ReactCompositeComponentMixin.mountComponent (node_modules / react / lib / ReactCompositeComponent.js: 262: 21)
    в Object.ReactReconciler.mountComponent (node_modules / react / lib / ReactReconciler.js: 47: 35)
    в ReactMultiChild.Mixin.mountChildren (node_modules / response / lib / ReactMultiChild.js: 242: 44)
    в ReactTestComponent.mountComponent (node_modules / react / lib / ReactTestRenderer.js: 53: 8)

Самый полезный комментарий

Согласно https://facebook.github.io/jest/docs/tutorial-react-native.html#mock -native-modules-using-jest-mock обходным путем является добавление

jest.mock('TextInput', () => 'TextInput');

к началу вашего теста.

Все 3 Комментарий

Согласно https://facebook.github.io/jest/docs/tutorial-react-native.html#mock -native-modules-using-jest-mock обходным путем является добавление

jest.mock('TextInput', () => 'TextInput');

к началу вашего теста.

Мы должны предоставить макет по умолчанию для TextInput.

Исправлено в https://github.com/facebook/jest/pull/1516 для Jest 15.

Была ли эта страница полезной?
0 / 5 - 0 рейтинги