From e069a77560372a8ce64d4961285d8e73ee312687 Mon Sep 17 00:00:00 2001 From: huangkairan <56213366+huangkairan@users.noreply.github.com> Date: Fri, 5 Feb 2021 22:48:17 +0800 Subject: [PATCH] fix(image): can't change image after set status to 'error' (#67) * resolve conflicts * test case Co-authored-by: huangkairan --- src/Image.tsx | 3 +++ tests/fallback.test.tsx | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Image.tsx b/src/Image.tsx index de698943..e17364dd 100644 --- a/src/Image.tsx +++ b/src/Image.tsx @@ -176,6 +176,9 @@ const ImageInternal: CompoundedComponent = ({ // Keep order end React.useEffect(() => { + if (isError) { + setStatus('normal'); + } if (isCustomPlaceholder) { setStatus('loading'); } diff --git a/tests/fallback.test.tsx b/tests/fallback.test.tsx index ff1eb3f6..d6aefbd7 100644 --- a/tests/fallback.test.tsx +++ b/tests/fallback.test.tsx @@ -58,4 +58,19 @@ describe('Fallback', () => { expect(onErrorMock).toHaveBeenCalledTimes(1); }); + + it('should change image, not error', () => { + const wrapper = mount(); + 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', + ); + }); + });