Questions tagged [babel-jest]

A Babel transpiler to assist with the conversion of ES6 to ES5 for the Jest testing framework.

A Babel plugin to assist ES6 to ES5 transpilation for the Jest testing framework.

607 questions
32
votes
5 answers

ReferenceError: React is not defined in jest tests

I have the following line that executes correctly in browser eval(Babel.transform(template, { presets: ['react'] }).code); but when I run jest tests I am getting ReferenceError: React is not defined What am I missing? More info: in the test file I…
chibis
  • 658
  • 2
  • 12
  • 22
32
votes
4 answers

React Jest causing "SyntaxError: Unexpected token ."

I am now using React Jest to test code. If a component is single, and not importing anything else, "npm test" runs smoothly. Now I want to test multiple components together, and I immediately get this error: SyntaxError: Unexpected token . It…
user3006967
  • 3,291
  • 10
  • 47
  • 72
27
votes
3 answers

reactjs jest jQuery is not defined

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 =…
user3006967
  • 3,291
  • 10
  • 47
  • 72
26
votes
2 answers

Testing ES6 class with Jest throws 'not a constructor' error

I found a similar problem here, but there doesn't seem to be an answer. I'm trying to test an ES6 class using Jest, like so: // src/myclass.js export default class MyClass { constructor(options) { // currently this is empty while I debug…
UnknownDeveloper
  • 445
  • 1
  • 4
  • 10
25
votes
5 answers

VueJS - Unit testing with vue-test-utils gives error - TypeError: _vm.$t is not a function

Relatively new to Vuejs and testing its components. Using vue-test-utils and jest for testing. Getting following error test log The .vue file consists of template, component and styling. Below is the part of the SignupLayout.vue that gets error -…
Karan Rao
  • 295
  • 2
  • 4
  • 7
23
votes
4 answers

How to setup jest with node_modules that use es6

I have a very simple test: describe('sanity', () => { it('sanity', () => { expect(true).toBeTruthy() }) }) And I'm receiving the following error: FAIL spec/javascript/sanity_test.js ● Test suite failed to run Jest encountered an…
Victor Pudeyev
  • 4,296
  • 6
  • 41
  • 67
23
votes
4 answers

babel@7 and jest configuration

Maybe you may help me? I try to configure jest to use babel@7 So I have: "jest": "^23.4.1", "@babel/core": "^7.0.0-beta.54", "babel-7-jest": "^21.3.3", "babel-jest": "^20.0.3", And jest config inside package.json "jest": { "transform": { …
SilentImp
  • 1,865
  • 1
  • 18
  • 28
21
votes
1 answer

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

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…
Luke Willis
  • 8,429
  • 4
  • 46
  • 79
20
votes
2 answers

Module /node_modules/vue-jest in the transform option was not found

I got an error and I need your help. Thank for watching this question. My situation: I am configuring Drone CI tool for my project and I get this when I run unit test on drone.yml. Validation Error: Module /node_modules/vue-jest in the…
Hoang Subin
  • 6,610
  • 6
  • 37
  • 56
18
votes
4 answers

Jest encountered an unexpected token + react markdown

I'm getting an error when trying to run my test file (I'm using react typescript) ● Test suite failed to run Jest encountered an unexpected token Jest failed to parse a file. This happens e.g. when your code or its dependencies use…
ng-someone
  • 321
  • 2
  • 9
16
votes
4 answers

How to import ".mjs" modules in Jest's xyz.test.js?

I want to use Import/export feature of ES6 modules (since my entire project uses that) with Jest 26.1.0. I have created a directory for my test cases called testCases/ which contains a math.mjs file. Now I am trying to import this file in…
Jatin Mehrotra
  • 9,286
  • 4
  • 28
  • 67
16
votes
1 answer

Jest unexpected token import from node_modules component; babel failing to run?

I'm trying to figure out how to get Jest to work in my environment, and I'm running into an issue where this project has a bunch of custom components in a subdirectory within node_modules. I'm getting this error: FAIL …
R Brennan
  • 715
  • 1
  • 6
  • 13
15
votes
4 answers

Next.js and Jest: SyntaxError: Cannot use import statement outside a module

I am working on a Next.js project using TypeScript and for testing I use Jest and React Testing Lib. However, I encounter a SyntaxError: Cannot use import statement outside a module for components where I import rehype-raw. As far as I understand…
Greeneco
  • 691
  • 2
  • 8
  • 23
15
votes
3 answers

Jest passing tests but --covering option not picking up files

Problem description: I have written two tests for a typescript class. Those two tests pass so jest successfully retrieves the test files. I then use the --coverage option but it appears jest is not picking the covered files here. Here is the output…
Jaro
  • 1,587
  • 5
  • 20
  • 39
15
votes
4 answers

.flat is not a function only with jest

When running my tests with jest, I had the above error; Error: Uncaught [TypeError: array.map(...).flat is not a function] Following the solution from that issue, https://github.com/kulshekhar/ts-jest/issues/828 I've installed core-js on…
Guilherme Bayer
  • 161
  • 1
  • 1
  • 4
1
2
3
40 41