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

Jest not picking up configs in multi project mode

We recently migrated two different repos into a monorepo. Each uses jest with its own custom configurations, defined in their own package.json files. I'd like to use the --projects flag to run Jest across both projects from the root of the monorepo.…
kgoggin
  • 169
  • 1
  • 12
9
votes
0 answers

Styled-components/macro doesn't work with Jest

I'm trying to integrate Jest, (ts-jest) into my typescript project which uses styled-components/macros. But for some reason, Jest is complaining with the following error: ts-jest[versions] (WARN) Version 4.0.2 of typescript installed has not been…
9
votes
3 answers

Jest - `Cannot create styled-component for component: undefined`

I'm running into the following error when testing my application using jest: FAIL ● Test suite failed to run Cannot create styled-component for component: undefined. 30 | 31 | > 32 | export const BackgroundVector =…
jxiao23
  • 155
  • 1
  • 4
9
votes
3 answers

console.error Error: Could not parse CSS stylesheet

I'm having the follow error when running my tests with jest. console.error Error: Could not parse CSS stylesheet at exports.createStylesheet ([PERSONAL_PATH]/node_modules/jsdom/lib/jsdom/living/helpers/stylesheets.js:34:21) at…
wviana
  • 1,619
  • 2
  • 19
  • 47
9
votes
3 answers

React Jest test fails to run with ts-jest - Unexpected token on imported file

I have a test for a test for a TSX file written in a JSX file which fails to run due to unexpected token: Test suite failed to run Jest encountered an unexpected token This usually means that you are trying to import a file which Jest…
Antfish
  • 1,313
  • 2
  • 22
  • 41
9
votes
3 answers

TypeError: Cannot assign to read only property 'x' of object '#' React/JEST
While I am writing test case for my react component I am getting TypeError: Cannot assign to read only property 'x' of object '#' wherein while the application run it does not throw similiar error The code for it is pretty…
Pragam Shrivastava
  • 1,428
  • 3
  • 13
  • 20
9
votes
3 answers

Code coverage "Unknown" using jest 15.1.1

When I try to include all the project source code to get a more reasonable code coverage figure, I end up with ----------|----------|----------|----------|----------|----------------| File | % Stmts | % Branch | % Funcs | % Lines |Uncovered…
boatcoder
  • 17,525
  • 18
  • 114
  • 178
9
votes
2 answers

XMLHttpRequest is not defined when testing react-native app with jest

i am trying to test a apiwrapper in a react-native based app using jest (integration testing). When i run it in the iOs simulator everything runs fine however it wont run my jest tests correctly - i always get: ReferenceError: XMLHttpRequest is not…
dschlossfr
  • 377
  • 5
  • 12
8
votes
1 answer

Updating CRA from version 4 to version 5 breaking babel-jest

After updating CRA to version 5. When running npm test I see the following error: Determining test suites to run... ● Test suite failed to run TypeError: babelJest.createTransformer is not a function at Object.
Felipe Plets
  • 7,230
  • 3
  • 36
  • 60
8
votes
4 answers

Jest and Babel transpilation - SyntaxError: Cannot use import statement outside a module

I struggle to use JEST for some cases where running the tests I get Test suite failed to run ...node_modules\p-retry\index.js:1 ({"Object.":function(module,exports,require,__dirname,__filename,jest){import retry from 'retry'; …
TomFree
  • 1,091
  • 3
  • 17
  • 31
8
votes
2 answers

Optional chaining issues when running test with jest

I am trying to run a test with Jest and I'm currently using jsx and tsx (changing from js to ts) in my react app but when I run my tests, all jsx tests are successful except those in tsx with optional blocking. I always get an error Unexpected token…
Henry Okonkwo
  • 363
  • 7
  • 17
8
votes
1 answer

Find component element by name in jest enzyme

component: console.log(component.find('div').at(0).childAt(0).find('input').find('search').debug()) error: doesn't show anything
NewbieCoder
  • 117
  • 1
  • 1
  • 6
8
votes
2 answers

Mock mounted hook Jest testing unit

I am doing some unit testing for components. However, in some components, I have something running on the mounted hook that is making my test fail. I have managed to mock the methods that I do not need. However, I was wondering if there is a…
heyr
  • 5,514
  • 11
  • 34
  • 55
8
votes
1 answer

How does jest allow mutation of modules?

In this question that I asked here: Why does mutating a module update the reference if calling that module from another module, but not if calling from itself? I'm asking about the nature of module mutation. However as it it turns out, ES6 modules…
dwjohnston
  • 11,163
  • 32
  • 99
  • 194
8
votes
1 answer

Jest mock not returning expected value

I've found that a mock I'm using, which will return a string, is seemingly returning jest.fn() rather than the "implementation" of the mock being jest.fn().mockImplementation(...). I'm calling it as so: const mockDefaultQuery = 'query { mock…
Bauza23
  • 191
  • 3
  • 18