From fca0da30e8e23385a2dbcc5f93586ed2b4b2d8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=81=8F=E5=8F=B3?= Date: Sun, 26 Jul 2020 16:53:50 +0800 Subject: [PATCH] fix: Avatar fallback bug (#25806) * refactor: avatar code * fix: Fix Avatar fallback bug close #25801 * add blank * update demo --- components/avatar/__tests__/Avatar.test.js | 19 ++++ .../__snapshots__/Avatar.test.js.snap | 10 ++ .../__tests__/__snapshots__/demo.test.js.snap | 19 ++++ components/avatar/demo/fallback.md | 37 ++++++++ components/avatar/index.tsx | 94 +++++++++---------- 5 files changed, 129 insertions(+), 50 deletions(-) create mode 100644 components/avatar/demo/fallback.md diff --git a/components/avatar/__tests__/Avatar.test.js b/components/avatar/__tests__/Avatar.test.js index a2e347376d..bd2ac2fc0f 100644 --- a/components/avatar/__tests__/Avatar.test.js +++ b/components/avatar/__tests__/Avatar.test.js @@ -158,4 +158,23 @@ describe('Avatar Render', () => { wrapper.simulate('mouseenter'); expect(onMouseEnter).toHaveBeenCalled(); }); + + it('fallback', () => { + const div = global.document.createElement('div'); + global.document.body.appendChild(div); + const wrapper = mount( + + A + , + { attachTo: div }, + ); + wrapper.find('img').simulate('error'); + wrapper.update(); + expect(wrapper).toMatchRenderedSnapshot(); + wrapper.detach(); + global.document.body.removeChild(div); + }); }); diff --git a/components/avatar/__tests__/__snapshots__/Avatar.test.js.snap b/components/avatar/__tests__/__snapshots__/Avatar.test.js.snap index fcd9fc7d27..82b960d2a6 100644 --- a/components/avatar/__tests__/__snapshots__/Avatar.test.js.snap +++ b/components/avatar/__tests__/__snapshots__/Avatar.test.js.snap @@ -1,5 +1,15 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Avatar Render fallback 1`] = ` + + + +`; + exports[`Avatar Render rtl render component should be rendered correctly in RTL direction 1`] = ` + + , + + + , +] +`; + exports[`renders ./components/avatar/demo/toggle-debug.md correctly 1`] = ` Array [