Questions tagged [jest-enzyme]
18 questions
3
votes
0 answers
Jest TypeError: Cannot read property 'body' of null
I am writing jest test case for a component but I keep getting this error:
/mnt/pinboard/webapp/node_modules/react-dom/cjs/react-dom.development.js:12056
throw error;
^
TypeError: Cannot read properties of null (reading 'body')
…

Simran Bhake
- 117
- 8
1
vote
0 answers
ReferenceError: TextEncoder is not defined jest, jest-enzyme
I'm trying to test react application with Jest and Enzyme (React v18, Jest v29.4.3, and Enzyme-adapter 16). The tests are simple as shown on the example below:
jest.test.file:
import React from 'react';
import Enzyme from 'enzyme';
import Adapter…

Moez Ben Rebah
- 170
- 1
- 12
1
vote
1 answer
TypeError: Cannot read property 'child' of undefined during mounting in enzyme unit tests
I need to mount a class component as I need to test all the components being rendered by it. But I think I am making some mistake in passing the props in it. This is my component:
class Marketing extends PureComponent {
constructor(props) {
…

Gareema
- 21
- 1
- 5
1
vote
1 answer
Babel error while running Jest/Enzyme tests on React Native
After a huge package upgrade, when running Jest tests on our application, we have this error :
TypeError: [BABEL] /home/grubshka/devel/project/src/engine/models/Hive.ts: Cannot add property 1, object is not extensible
at Array.push ()
…

Grubshka
- 533
- 4
- 9
1
vote
1 answer
writing test case using jest-enzyme/react-testing library
I'm completely new to writing test cases.I'm trying to write test case using jest,enzyme/react-testing library.I'm unable to test this component,tets are failing .If anyone can help me to write the test for the below code .Thank you in advance... I…

Veda
- 11
- 2
0
votes
0 answers
How to mock function in Jest for Functional component using Enzyme
I am trying to write a jest test for the functional component using enzyme. I am having a component inside that I am having a method which returns the jsx elements. Out of three elements two are dropdown elements. I need to write test for that two…

roshan26
- 1
- 2
0
votes
1 answer
How to achieve 100% in unit testcase writing for React native functional component?
I have tried to write test case using jest as matcher and React NativeTesting library as a test base. But I can't reach the 100% test coverage.
I have tried to mock the use effect and use state hooks but I won't mock that still it's asking for to…

Balaji Govindaraj
- 13
- 2
0
votes
0 answers
After update to react 18, enzyme library's mount function is throwing error - TypeError: Cannot read property '_reactInternals' of null
I have upgraded react from 17.0.2 to 18.2.0. I have also added enzyme adapter: https://github.com/cfaester/enzyme-adapter-react-18. However, the mount function in enzyme is throwing the error: TypeError: Cannot read property '_reactInternals' of…

Saad Farooq
- 39
- 1
- 8
0
votes
1 answer
Jest Enzyme: TypeError: Cannot read property 'getBoundingClientRect' of null
Can anyone help please: TypeError: Cannot read property 'getBoundingClientRect' of null.
handleInformationIcon = (setIndex, index) => {
this.setState({ TooltipCheck: !this.state.TooltipCheck, activeTooltip: setIndex });
const toolTipElement…

varsha94
- 249
- 1
- 6
- 22
0
votes
0 answers
Unable to get success in react native jest test cases for Image and Image Background components while using local assets
I am writing test cases for ImageBackground and Image component in React native but the test cases is getting failed as I am using local assets. It is unable to fetch the location of the assets folder I guess. Can someone help me out with this…
0
votes
0 answers
Enzyme: React DOM being updated after simulating a click, but not the resulting .html()
I wanted to share this puzzling behavior, as, googling, I've found problems which are similar but decidedly not the same.
While I cannot share the exact code I can illustrate what I mean with the following…

DeadlyBacon
- 531
- 4
- 17
0
votes
0 answers
I want to test click event on group of buttons . while adding into a loop it throws simulate is not a function ,
const buttons: IButton[] = [
{
children: 'Back',
variant: 'gray',
onClick: mockCallBack
},
{
children: 'Skip Recommended',
onClick: mockCallBack
},
{
children: 'Next',
onClick: mockCallBack
},
];
getting this error :
TypeError:…
0
votes
0 answers
Can i check multiple function call using jest/enzyme?
I have onchange callback(been called from child to parent) function in one of the component
i was trying to simulate onchange function as shown but i am getting error as
'getchangeChecbox' is not a function
childcomponent

R9102
- 687
- 1
- 9
- 32
0
votes
1 answer
How to write unit tests for a function call in a div in enzyme and jest?
I have a function call in my react component. I need to write the unit tests for it.
Here is my function definition:
const renderError = () =>{
const {isError, errorMessage, errorFromWhere} = error;
if(isError && errorFromWhere ===…

Gareema
- 21
- 1
- 5
0
votes
1 answer
TypeError: Cannot read property 'showPrev' of undefined while writing unit test cases in enzyme
I am writing unit tests using jest and enzyme to test my functional component. I am just checking whether the div is getting rendered or not, but I get the error:
TypeError: Cannot read property 'showPrev' of undefined
Here is my component:
…

Gareema
- 21
- 1
- 5