简体   繁体   English

开玩笑-TypeError:无法读取未定义的属性“项目”

[英]Jest - TypeError: Cannot read property 'projects' of undefined

So I am starting to do unit testing of my React-Native application. 因此,我开始对React-Native应用程序进行单元测试。 I just wanted to try the first test and I immediately get errors. 我只是想尝试第一个测试,所以我立即收到错误消息。

Here is what my test looks like: 这是我的测试结果:

 import 'react-native'; import React from 'react'; import Index from '../index.ios.js'; // Note: test renderer must be required after react-native. import renderer from 'react-test-renderer'; it('renders correctly', () => { const tree = renderer.create( <Index /> ).toJSON(); expect(tree).toMatchSnapshot(); }); 

and here is my package JSON 这是我的包JSON

 { "name": "project", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest", "build": "npm install && react-native link && react-native run-ios" }, "dependencies": { "anymatch": "^1.3.0", "native-base": "^2.2.0", "react": "16.0.0-alpha.12", "react-native": "0.45.1", "react-native-datepicker": "^1.6.0", "react-native-elements": "^0.13.0", "react-native-local-notifications": "^0.1.0", "react-native-maps": "^0.15.2", "react-native-notifications": "^1.1.11", "react-native-sound": "^0.10.3", "react-native-swipeout": "^2.1.3", "react-native-vector-icons": "^4.2.0", "react-navigation": "^1.0.0-beta.11", "react-redux": "^5.0.5", "redux": "^3.7.1", "redux-logger": "^3.0.6", "redux-thunk": "^2.2.0" }, "devDependencies": { "babel-jest": "20.0.3", "babel-preset-react-native": "2.0.0", "jest": "20.0.4", "react-test-renderer": "16.0.0-alpha.12" }, "jest": { "preset": "react-native" } } 

The error I get is this : 我得到的错误是这样的:

TypeError: Cannot read property 'projects' of undefined
at /Users/grantherman/Desktop/project/node_modules/jest/node_modules/jest-cli/build/cli/runCLI.js:106:25
at Generator.next (<anonymous>)
at step (/Users/grantherman/Desktop/project/node_modules/jest/node_modules/jest-cli/build/cli/runCLI.js:1:260)
at /Users/grantherman/Desktop/project/node_modules/jest/node_modules/jest-cli/build/cli/runCLI.js:1:490
at Promise (<anonymous>)
at /Users/grantherman/Desktop/project/node_modules/jest/node_modules/jest-cli/build/cli/runCLI.js:1:171
at module.exports (/Users/grantherman/Desktop/project/node_modules/jest/node_modules/jest-cli/build/cli/runCLI.js:139:50)
at Object.run (/Users/grantherman/Desktop/project/node_modules/jest/node_modules/jest-cli/build/cli/index.js:40:3)
at Object.<anonymous> (/Users/grantherman/Desktop/project/node_modules/jest/node_modules/jest-cli/bin/jest.js:14:25)
at Module._compile (module.js:569:30)

I literally have no idea why. 我真的不知道为什么。 I have looked around and no one has experienced the same error as this. 我环顾四周,没有人遇到过与此相同的错误。

Under jest in your package.json , try adding "testEnvironment": "jsdom" package.json jest下,尝试添加"testEnvironment": "jsdom"

"jest": {
  "preset": "react-native",
  "testEnvironment": "jsdom"
}

I dont see jest-cli in your packages.json. 我在您的packages.json中看不到jest-cli。 I had the exact same issue with reactjs. 我对reactjs有完全相同的问题。 Installing jest-cli (I only had jest) fixed the issue. 安装jest-cli(我只有jest)解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jest - TypeError:无法读取未定义的属性“fn” - Jest - TypeError: Cannot read property 'fn' of undefined Jest TypeError:无法读取未定义的属性“id” - Jest TypeError: Cannot read property 'id' of undefined 开玩笑:TypeError:无法读取未定义的属性“长度” - Jest : TypeError: Cannot read property 'length' of undefined TypeError:无法读取未定义的 Jest 和 Nest 的属性“then” - TypeError: Cannot read property 'then' of undefined Jest and Nest JEST - TypeError:无法读取未定义的属性“then” - JEST - TypeError: Cannot read property 'then' of undefined JEST TypeError:无法读取未定义的属性“json” - JEST TypeError: Cannot read property 'json' of undefined 类型错误:无法在玩笑测试中读取未定义的属性“原型” - TypeError: Cannot read property 'prototype' of undefined in jest test React Native jest test:TypeError:无法读取未定义的属性&#39;unsubscribeFromTopic&#39; - React Native jest test: TypeError: Cannot read property 'unsubscribeFromTopic' of undefined Jest - 测试给出错误类型错误:无法读取未定义的属性“then” - Jest - Test gives an error TypeError: Cannot read property 'then' of undefined 类型错误:无法读取未定义的笑话酶的属性“值” - TypeError: Cannot read property 'value' of undefined jest enzyme
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM