Facing `Cannot read property 'refs' of undefined` for Tests with enzyme mount wrapper on component having material ui components
See original GitHub issueAfter including this library and adding the setup, able to pass tests fromuseEffect
actions seamlessly which I couldn’t do with other solutions.
But soon, all the other test components (where mount
wrapper of enzyme is used and the components are usingmaterial-ui
components) started throwing throwing the error Cannot read property 'refs' of undefined
error.
Sample Test Component:
//TestComponent.js
import React, { useState } from 'react';
import TextField from '@material-ui/core/TextField';
const TestComponent = () => {
return (
<TextField value="somedata" />
}
}
export default TestComponent;
//TestComponent.test.js
import React from 'react';
import { mount } from 'enzyme';
import TestComponent from '../TestComponent';
describe('TestComponent', () => {
Date.now = jest.fn(() => 123);
it('matches snapshot', () => {
const componentWrapper = mount(<TestComponent />);
expect(componentWrapper).toMatchSnapshot();
});
});
But, Not getting error when i try using useRef and ForwardRef’s inside the component Not getting error with material-ui components too when I exclude this package from setup… Any work around for this would be welcomed?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
React test with Enzyme, cannot read property 'route' of ...
test ('Make sure the componentDidMount being called after mount', () => { sinon.spy(myComponent.prototype, 'componentDidMount'); const component ...
Read more >enzymejs/enzyme - Gitter
hi guys, I have issue with enzyme's mount method. It crashing ONLY when im trying to use mount, when use shallow everything works...
Read more >Migrate from Enzyme | Testing Library
This page is intended for developers who have experience with Enzyme and are trying to understand how to migrate to React Testing Library....
Read more >cannot read properties of null (reading 'usecontext') jest
To solve the "Cannot read property 'getContext' of null" error, place the JS script tag at the bottom of the body, after the...
Read more >Cannot read property search of undefined this props location ...
TypeError : Cannot read property 'apply' of undefined I have 2 components/tests Login. props and this. I need help with webpack, version 3...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @krajasekhar ,
Thanks you for reporting that! I haven’t tested it with
mount()
, but I’ll have a look into the problem and will come back to you!@mikeborozdin - Closing the ticket.