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
8
votes
1 answer

How to get CSS style in snapshot with Jest

I have the following question, I don't know if its possible to get the result using Jest + snapshot feature. I have a React components and I'm using Jest to test it. I want the snapshot to include css style not className. Currently my snapshot is…
Boba Fett likes JS
  • 747
  • 3
  • 10
  • 21
8
votes
2 answers

Jest - mock fat arrow function within React component

Given my component and test below, why does my confirmClickHandler method still get called when I run my test? Note: I noticed that when I change the method from a fat arrow function to just a regular function, it gets mocked out correctly. What…
JoshieWashie
  • 81
  • 1
  • 3
8
votes
2 answers

Jest pattern "" - 0 matches (moving from jest 19 -> jest 20)

I'm using the following jest.unittest.json file (used via jest --config option): { "bail": false, "verbose": true, "transform": { "^.+\\.(ts|tsx)$": "typescript-babel-jest" }, "testPathIgnorePatterns": [ "/lib", …
Dev Doomari
  • 943
  • 10
  • 19
7
votes
2 answers

Why does the stack trace for my jest tests point to the wrong line numbers?

When I run jest tests in my repo containing errors, the stack trace points to the wrong line numbers. This makes it very difficult to debug. For example: Expected error ● SimpleComponent › renders ReferenceError: retur is not defined 4…
bluprince13
  • 4,607
  • 12
  • 44
  • 91
7
votes
1 answer

How to use jest with node_modules using es6 within NX project

I have a project with NX structure(apps + libs). And I am writing tests for react + typescript lib. I faced the issue when I try to use suneditor + suneditor-react: Jest encountered an unexpected token Jest failed to parse a file. This happens…
Volha
  • 71
  • 1
  • 4
7
votes
1 answer

Difference between jest.fn(implementationCallback) and jest.fn().mockImplementation(implementationCallback)

I've noticed we got the same behavior when we jest.fn() with the implementation passed as param in the .fn() and jest.fn().mockImplementation(). If so, choosing the fit is jut a matter of tastes? Example: jest.fn((num1, num2) => num1 + num2) // same…
Jhonatan
  • 1,191
  • 2
  • 10
  • 21
7
votes
2 answers

Jest test with TypeScript does not recognize import alias

I'm setting up the tests for my web application, which works with the Vue framework with TypeScript, using the Jest framework. Everything seems to work alright, except with the @ symbol in my imports, e.g., import { Foo } from '@/bar. Whether it's…
Bastian Nanchen
  • 672
  • 1
  • 13
  • 24
7
votes
1 answer

Jest TypeError: is not a constructor in Jest.mock

I am trying to write a unit test case using jest and need to mock the below pattern . I am getting TypeError: is not a constructor. Usecase : My usecase is as mentioned below MyComponent.js : import serviceRegistry from…
girish TS
  • 209
  • 1
  • 3
  • 10
7
votes
0 answers

How can I solve " TypeError: Cannot set property '_eventListeners' of undefined" with jest

I have a vue.js application, and I installed Jest using these instruction: https://vue-test-utils.vuejs.org/guides/testing-single-file-components-with-jest.html. when I run npm test, I get the error. ● Test suite failed to run TypeError: Cannot…
emmanuel agarry
  • 335
  • 3
  • 8
7
votes
3 answers

Jest 24.0.0 Plugin/Preset files are not allowed to export objects, only functions

After upgrading from Jest 23.6.0 to 24.0.0 I'm getting this error: Plugin/Preset files are not allowed to export objects, only functions. This is caused by this commit: https://github.com/facebook/jest/pull/7203/files which documents the breaking…
Guy
  • 65,082
  • 97
  • 254
  • 325
7
votes
1 answer

Configuring Babel and Jest

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…
nomadoda
  • 4,561
  • 3
  • 30
  • 45
7
votes
4 answers

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

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:…
J. Hesters
  • 13,117
  • 31
  • 133
  • 249
7
votes
2 answers

Jest with React Native getting issue

I'm getting error when trying to run test cases code.i am using react native with jest . all was working fine before upgrade 0.40 . now is 0.42 all my test cases stop working and getting error following…
Sport
  • 8,570
  • 6
  • 46
  • 65
7
votes
1 answer

JEST test not understanding import statement

Im using JEST to test my app. But Im getting an error from the test file -- import xyz from './XYZ.js'; ^^^^^^ SyntaxError: Unexpected token import Then I created a .babelrc file and it has the following code -- { "presets": [ "es2015" …
Ivin
  • 4,435
  • 8
  • 46
  • 65
7
votes
0 answers

What can impact the speed of tests ran with Jest?

I got Jest working in my environment, but I'm fairly certain that it's running way slower than it's supposed to. Currently, I'm just running 2 tests that are copied from the Jest intro tutorials. One is a simple sum function, and another is a…
thisissami
  • 15,445
  • 16
  • 47
  • 74