`useEffect` not called when the component is `shallow` renderered
### Current behavior `useEffect` fonction does not seem to be executed when the component is rendered with `shallow`. Given the following simple component using `useEffect` hook to call a method given as a prop: ``` import React, { useEffect } from 'react'; export const MyComponent = ({ callback }) => { useEffect(() => { callback('Say something'); }); return <div>Hello world!</div>; }; ``` And the following tests checking that the `callback` function is indeed called accordingly: ``` import React from 'react'; import { shallow, mount } from 'enzyme'; import { MyComponent } from '../MyComponent'; describe('MyComponent', () => { describe('shallow render', () => { it('should call callback when shallow rendered', () => { const callback = jest.fn(); shallow(<MyComponent callback={callback} />); expect(callback).toHaveBeenCalled(); }); }); describe('mount', () => { it('should call callback when mounted', () => { const callback = jest.fn(); mount(<MyComponent callback={callback} />); expect(callback).toHaveBeenCalled(); }); }); }); ``` We observe that the method is called as expected when "mounted", but not when using a `shallow` renderer: ``` FAIL src/tests/MyComponent.test.js MyComponent shallow render ✕ should call callback when shallow rendered (12ms) mount ✓ should call callback when mounted (24ms) ● MyComponent › shallow render › should call callback when shallow rendere
Posted by jlandic on Apr 8, 2019, 9:17 AM
Tags
Related issues
- The issue is really the extreme difficulty of programming them, especially for anything sequential (rather than combinatorial).
- I probably could have beared with it if it was only limited to programming, but it showing up in creative fields has made me feel all sor...
- I hate that I'm in deep enough to know what you mean.
- The biggest problem with “AI” is that big corps are shoving it down our throats.
- in the middel of a coding session with 5.6 sol.
- [Hero Run] 535B-A23B on 18T tokens
Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments
reliability (Other)
The issue is really the extreme difficulty of programming them, especially for anything sequential (rather than combinatorial).
I probably could have beared with it if it was only limited to programming, but it showing up in creative fields has made me feel all sor...
I hate that I'm in deep enough to know what you mean.
The biggest problem with “AI” is that big corps are shoving it down our throats.
in the middel of a coding session with 5.6 sol.
[Hero Run] 535B-A23B on 18T tokens
I hate that this is how AI is being used..
inexperienced protobuf user here -- why do non-googlers generally use protobuf?
`useEffect` not called when the component is `shallow` renderered
### Current behavior `useEffect` fonction does not seem to be executed when the component is rendered with `shallow`. Given the following simple component using `useEffect` hook to call a method given as a prop: ``` import React, { useEffect } from 'react'; export const MyComponent = ({ callback }) => { useEffect(() => { callback('Say something'); }); return <div>Hello world!</div>; }; ``` And the following tests checking that the `callback` function is indeed called accordingly: ``` import React from 'react'; import { shallow, mount } from 'enzyme'; import { MyComponent } from '../MyComponent'; describe('MyComponent', () => { describe('shallow render', () => { it('should call callback when shallow rendered', () => { const callback = jest.fn(); shallow(<MyComponent callback={callback} />); expect(callback).toHaveBeenCalled(); }); }); describe('mount', () => { it('should call callback when mounted', () => { const callback = jest.fn(); mount(<MyComponent callback={callback} />); expect(callback).toHaveBeenCalled(); }); }); }); ``` We observe that the method is called as expected when "mounted", but not when using a `shallow` renderer: ``` FAIL src/tests/MyComponent.test.js MyComponent shallow render ✕ should call callback when shallow rendered (12ms) mount ✓ should call callback when mounted (24ms) ● MyComponent › shallow render › should call callback when shallow rendere
Comments (0)
No comments yet. Start the discussion.