babel-jest

Jest: Test suite failed to run, Unexpected token =

我与影子孤独终老i 提交于 2020-01-05 08:39:31
问题 I am trying to test a React component with Jest/Enzyme. I expect the test to at least run, but it already fails when it is importing files and does not get to the test itself. So I am wondering what in the configuration I am missing? Error: __tests__/Favorite.test.js ● Test suite failed to run /src/components/favorite/Favorite.js: Unexpected token (13:13) 11 | } 12 | > 13 | isFavorite = (props) => { | ^ 14 | return localStorage.getItem(props.recipe.id) ? true : false 15 | } 16 | Test File:

Unexpected token import error in while running jest tests

我怕爱的太早我们不能终老 提交于 2020-01-04 09:27:30
问题 I know this has been asked countless times, but I am not able to fix the problem inspite of following all the SO solutions and suggestions. I came to know about jest a few days ago and tried to have my hands on it. There is a good tutorial mentioned on DZone about using jest to test react components. However, when I try testing one of the components from the starter directory, I am having this issue, SyntaxError: Unexpected token import at ScriptTransformer._transformAndBuildScript (../../../

Jest from create-react-app not running on Windows

我们两清 提交于 2020-01-04 02:58:09
问题 I have a problem running Jest from a clean installed app created using create-react-app on Windows 8.1. After the installation, running the command npm run test , I get the error: No tests found related to files changed since last commit. Running jest --watchAll , so bypassing the react-scripts, in the same directory, though, shows: Test suite failed to run 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

What is the state of the art for testing/mocking functions within a module in 2018?

余生颓废 提交于 2020-01-04 01:29:58
问题 I have a module, for the purposes of learning testing, that looks like this: api.js import axios from "axios"; const BASE_URL = "https://jsonplaceholder.typicode.com/"; const URI_USERS = 'users/'; export async function makeApiCall(uri) { try { const response = await axios(BASE_URL + uri); return response.data; } catch (err) { throw err.message; } } export async function fetchUsers() { return makeApiCall(URI_USERS); } export async function fetchUser(id) { return makeApiCall(URI_USERS + id); }

reactjs jest jQuery is not defined

流过昼夜 提交于 2020-01-01 03:58:27
问题 I am using jest to test my reactJS component. In my reactJS component, I need to use jquery UI, so I added this in the component: var jQuery = require('jquery'); require('jquery-ui/ui/core'); require('jquery-ui/ui/draggable'); require('jquery-ui/ui/resizable'); And it worked fine. But, now, I need to used jest to do testing, but I immediately meet this issue when I load the component into testutils, Test suite failed to run ReferenceError: jQuery is not defined Has anyone met this issue if

Required babel-jest dependency

可紊 提交于 2019-12-23 22:12:30
问题 I am new in the topic of React. I started it recently and I have a problem when I want to start a React app. 'yarn start' shows this error: The react-scripts package provided by Create React App requires a dependency: "babel-jest": "23.6.0" How can I overcome this error, please. I tried to find a solution on Internet but I was not lucky. Where is the problem, please? 回答1: So it looks like what might have happened was that after you created a new app using create-react-app . you then manually

webpack require non-js content in jest unit-tests

白昼怎懂夜的黑 提交于 2019-12-23 12:08:03
问题 Recently I've converted one of my projects to webpack & babel. It is made out of knockout components. I'm running into a problem while running the unit-tests. If I have a file in the tests folder like import component from '../custom-options'; test('adds 1 + 2 to equal 3', () => { expect(3).toBe(3); }); The problem is that the component is a module which has a require of the sort var htmlString = require('./custom-options.html'); When I try to run the website itself it runs fine, as the raw

React Native - Jest: Broken since update to 0.56. How to fix it?

让人想犯罪 __ 提交于 2019-12-23 09:46:55
问题 Ever since upgrading to the new React Native version my tests are broken. Environment Here is my environment: React Native Environment Info: System: OS: macOS High Sierra 10.13.4 CPU: x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz Memory: 486.81 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 9.4.0 - /usr/local/bin/node npm: 6.1.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3 IDEs: Android Studio:

Jest not using manual mock

混江龙づ霸主 提交于 2019-12-23 03:44:15
问题 I'm using Create React App. I created a Jest test that uses a manual mock. The test renders my App component and I'm trying to mock a nested component. It's still picking up the original BarChart component. containers/__tests__/App.js import React from 'react'; import { shallow, mount } from 'enzyme'; const barChartPath = '../../components/d3/BarChart/BarChart'; describe('App', () => { beforeEach(() => { const mockBarChart = require('../../components/d3/BarChart/__mocks__/BarChart').default;

Integration testing of Relay containers with Jest against a working GraphQL backend not working

懵懂的女人 提交于 2019-12-23 01:36:24
问题 I'd like to implement the integration testing of my Relay containers against a running GraphQL backend server. I'm going to use Jest for this. I'd like to say that unit testing of React components works well as expected with my Jest setup. Here's what I have in the package.json for the Jest: "jest": { "moduleFileExtensions": [ "js", "jsx" ], "moduleDirectories": [ "node_modules", "src" ], "moduleNameMapper": { "^.+\\.(css|less)$": "<rootDir>/src/styleMock.js", "^.+\\.(gif|ttf|eot|svg|png)$":