babel-jest

jest test fails after installing react-native-async-storage

萝らか妹 提交于 2019-12-22 04:46:24
问题 In my react native project, I have recently installed node module react-native-async-storage as I received warnings about the native package from 'react-native' being deprecated and moved out to an individual module. After installing the @react-native-community/async-storage my jest test is failing. first with following error: unexpected token at position 0 in file: persistence.js import AsyncStorage from '@react-native-community/async-storage'; storeData = async ({ key, value }) => { try {

Jest: Error when trying to import Native Modules; unable to prevent with Mock

眉间皱痕 提交于 2019-12-13 21:13:51
问题 I've recently been brought on to a team as Test Engineer and I'm trying to get Jest unit tests up and running on our React Native app. My predecessor has already authored dozens of unit tests, most of which are not running successfully. I'm getting the following error when running npm test FAIL __tests__/index.test.js ● Test suite failed to run TypeError: Cannot read property '_addDeviceToGroup' of undefined 4 | } from 'react-native'; 5 | const { > 6 | _addDeviceToGroup, | ^ 7 | } =

How to configure Jest to work with Expo SDK 32

会有一股神秘感。 提交于 2019-12-13 16:45:06
问题 I have an Expo app and was using SDK 28. My team decided we should update to the latest version, that meant updating React Native (Since the latest SDK uses RN 0.57) and Babel. When we updated our dependencies, and fixed our config files, Jest started to give us this error: TypeError: Cannot read property 'fetch' of undefined at node_modules/react-native/Libraries/vendor/core/whatwg-fetch.js:6:12 at Object.<anonymous> (node_modules/react-native/Libraries/vendor/core/whatwg-fetch.js:486:3) at

What is the difference between babel-core and @babel/core?

半腔热情 提交于 2019-12-13 12:23:46
问题 What is the difference between babel-core and @babel/core ? Are they the same thing but different versions? If not so, when do you use one and when do you use the other? Thank you. 回答1: Since Babel 7 the Babel team switched to scoped packages, so you now have to use @babel/core instead of babel-core . But in essence, @babel/core is just a newer version of babel-core . This is done to make a better distinction which packages are official and which are third-party. 来源: https://stackoverflow.com

Babel 7 Jest Core JS Typeerror wks is not a function

六月ゝ 毕业季﹏ 提交于 2019-12-11 17:50:41
问题 After upgrading my project to Babel 7, running tests through jest is throwing the following error. The tests used to run without any issues in Babel 6, but are failing in Babel 7 with the following error TypeError: wks is not a function at Object.<anonymous>.module.exports (node_modules/core-js/modules/_fix-re-wks.js:16:16) at Object.<anonymous> (node_modules/core-js/modules/es6.regexp.replace.js:4:25) at Object.<anonymous> (node_modules/core-js/modules/es6.regexp.split.js:3:1) at Object.

jest encountered unexpected token

我是研究僧i 提交于 2019-12-11 08:04:32
问题 I am facing this issue. after running my unit test. This same error occurs wherever the static variable present. do you have any solution for this? or what causing this issue similarly, the same error showing for the auto binding too. ex: handle = ()=>{ } 回答1: finally, I found the solution. add this below lines in the babelrc file "presets": ["env", "react"], "plugins": ["transform-class-properties"] And also if someone facing below issue, Kindly check your node version. it should be 8+

How to transform module after ordinary transform has run in jest

人盡茶涼 提交于 2019-12-11 02:33:40
问题 Testing React components with jest. Some of these components make use of OpenLayers (ol package v5.2.0). In ol package v4 I applied transformIgnorePatterns to have the ol package transformed: "jest": { "transformIgnorePatterns": [ "node_modules/(?!(ol)/)" ], (...) } Now I get the following error when running NODE_ENV=test jest : (...) (...)/node_modules/ol/index.js:5 export {default as AssertionError} from './AssertionError.js'; ^^^^^^ SyntaxError: Unexpected token export 14 | let map = new

Configuring Babel and Jest

筅森魡賤 提交于 2019-12-10 09:24:22
问题 TLDR: How can I configure jest so that it uses babel to compile the test files and the files required in globalSetup and globalTeardown ? I've been struggling a lot to configure jest and babel . It seems that when I run my tests babel fails to load the configuration file, or perhaps it doesn't run at all. in package.json: { "scripts": { "start": "babel-node src/index.js", "test": "jest src/tests/*.test.js", }, "devDependencies": { "@babel/cli": "^7.0.0-rc.1", "@babel/core": "^7.0.0-rc.1", "

“Define is not defined” in Jest when testing es6 module with RequireJS dependency

爱⌒轻易说出口 提交于 2019-12-09 14:44:08
问题 I have a Jest test suite that fails to run because the component it's trying to test depends on a RequireJS module. Here's the error I'm seeing: FAIL __tests__/components/MyComponent.test.js ● Test suite failed to run ReferenceError: define is not defined at Object.<anonymous> (node_modules/private-npm-module/utils.js:1:90) The component has the following import: import utils from 'private-npm-module'; And the private-npm-module is set up like so: define('utils', [], function() { return {}; }

Unexpected token 'import' error while running Jest tests?

扶醉桌前 提交于 2019-12-06 19:03:02
问题 I realize this question has been asked several times but all of the solutions I've come across don't seem to work for me. I'm running into the following error while trying to run Jest tests for a Vue app. Jest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript. By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules". Here's what you can do: • To have