Skip to content

Commit

Permalink
fix(image): can't change image after set status to 'error' (#67)
Browse files Browse the repository at this point in the history
* resolve conflicts

* test case

Co-authored-by: huangkairan <[email protected]>
  • Loading branch information
huangkairan and huangkairan authored Feb 5, 2021
1 parent 58ec0e6 commit e069a77
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ const ImageInternal: CompoundedComponent<ImageProps> = ({
// Keep order end

React.useEffect(() => {
if (isError) {
setStatus('normal');
}
if (isCustomPlaceholder) {
setStatus('loading');
}
Expand Down
15 changes: 15 additions & 0 deletions tests/fallback.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,19 @@ describe('Fallback', () => {

expect(onErrorMock).toHaveBeenCalledTimes(1);
});

it('should change image, not error', () => {
const wrapper = mount(<Image width={200} src="error" fallback='https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png' />);
act(() => {
wrapper.setProps({
src: 'https://gw.alipayobjects.com/mdn/rms_08e378/afts/img/A*NZuwQp_vcIQAAAAAAAAAAABkARQnAQ',
});
jest.runAllTimers();
wrapper.update();
});
expect(wrapper.find('.rc-image-img').prop('src')).toBe(
'https://gw.alipayobjects.com/mdn/rms_08e378/afts/img/A*NZuwQp_vcIQAAAAAAAAAAABkARQnAQ',
);
});

});

1 comment on commit e069a77

@vercel
Copy link

@vercel vercel bot commented on e069a77 Feb 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.