Jest: React Nativeスナップショットは、「TypeError:Undefinedのプロパティ '_tag'を読み取れません」で失敗します。<textinput/>

作成日 2016年08月06日  ·  3コメント  ·  ソース: facebook/jest

再現するには:

  1. https://github.com/facebook/jest/blob/master/examples/react-native/Intro.jsを変更して、render()に<TextInput />を追加します
  2. npmテスト

結果:

FAILテスト/Intro-test.js(0.459s)
●イントロ›正しくレンダリングされます

  • TypeError:未定義のプロパティ '_tag'を読み取れません
    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 / react / 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のデフォルトのモックを提供する必要があります。

Jest15のhttps://github.com/facebook/jest/pull/1516で修正されました。

このページは役に立ちましたか?
0 / 5 - 0 評価