尝试测试我的React-native组件时出错。 `TypeError:_this._scrollView.scrollTo不是函数`

时间:2017-10-28 00:32:39

标签: javascript node.js react-native jestjs

我正在尝试为我的React-native应用程序进行一些单元测试,但我在这里遇到了一个奇怪的问题。我不知道问题出在哪里。我查看了React-native GitHub和StackOverFlow,但我找不到任何解决方案。

因此,当我尝试在我的测试文件hostvars

上运行此代码时
App.test.js

我的import React from 'react'; import App from '../../App'; import renderer from 'react-test-renderer'; it('renders without crashing', () => { const rendered = renderer.create(<App />).toJSON(); expect(rendered).toBeTruthy(); });

Package.json

每次尝试运行{ "name": "Flashcards", "version": "0.1.0", "private": true, "devDependencies": { "jest-cli": "20.0.4", "jest-expo": "^21.0.2", "react-dom": "^16.0.0", "react-native-scripts": "1.5.0", "react-script": "^2.0.5", "react-test-renderer": "^16.0.0" }, "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js", "scripts": { "start": "react-native-scripts start", "eject": "react-native-scripts eject", "android": "react-native-scripts android", "ios": "react-native-scripts ios", "test": "node node_modules/jest/bin/jest.js --watch" }, "jest": { "preset": "jest-expo" }, "dependencies": { "array-shuffle": "^1.0.1", "date-fns": "^1.29.0", "expo": "^21.0.0", "prop-types": "^15.6.0", "react": "16.0.0-alpha.12", "react-native": "^0.48.4", "react-native-keyboard-aware-scroll-view": "^0.4.1", "react-navigation": "^1.0.0-beta.15", "remote-redux-devtools": "^0.5.12" } } yarn test

时出现的错误
npm test

这是我的App.js.顺便说一下,应用程序工作得很好

 FAIL  src/__test__/App.test.js
  ● renders without crashing

    TypeError: _this._scrollView.scrollTo is not a function

      at TabViewPagerScroll._this._scrollTo (node_modules/react-native-tab-view/src/TabViewPagerScroll.js:90:19)
      at TabViewPagerScroll.componentDidMount (node_modules/react-native-tab-view/src/TabViewPagerScroll.js:113:259)
      at commitLifeCycles (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5461:24)
      at commitAllLifeCycles (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6250:9)
      at Object.invokeGuardedCallback$1 (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2159:10)
      at invokeGuardedCallback (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2106:29)
      at commitAllWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6371:9)
      at workLoop (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6643:13)
      at Object.invokeGuardedCallback$1 (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2159:10)
      at invokeGuardedCallback (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2106:29)

  ✕ renders without crashing (62ms)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        0.143s, estimated 1s
Ran all test suites related to changed files.

  console.error node_modules/react-native/Libraries/Core/ExceptionsManager.js:73
    The above error occurred in the <TabViewPagerScroll> component:
        in TabViewPagerScroll (created by TabViewAnimated)
        in View (created by View)
        in View (created by TabViewAnimated)
        in TabViewAnimated (created by TabView)
        in TabView (created by withCachedChildNavigation(TabView))
        in withCachedChildNavigation(TabView)
        in Unknown (created by Navigator)
        in Navigator (created by NavigationContainer)
        in NavigationContainer (created by App)
        in View (created by View)
        in View (created by App)
        in Provider (created by App)
        in App

    Consider adding an error boundary to your tree to customize error handling behavior.
    You can learn more about error boundaries at

谢谢

0 个答案:

没有答案