From d55cdf28c7e2fe870527449d8b4571a9ffa36a41 Mon Sep 17 00:00:00 2001 From: wendzhue Date: Sun, 19 Aug 2018 17:05:34 +0800 Subject: [PATCH] fix(module:avatar): tolerate error src (#2008) * fix(module:avatar): tolerate error src * fix lint --- components/avatar/avatar.spec.ts | 23 +++++++++++++++++++++-- components/avatar/nz-avatar.component.ts | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/components/avatar/avatar.spec.ts b/components/avatar/avatar.spec.ts index 778f07de40b..312b116e055 100644 --- a/components/avatar/avatar.spec.ts +++ b/components/avatar/avatar.spec.ts @@ -27,8 +27,27 @@ describe('avatar', () => { fixture.detectChanges(); }); - it('#nzSrc', () => { - expect(context).not.toBeNull(); + describe('#nzSrc', () => { + it('#nzSrc', () => { + expect(context).not.toBeNull(); + }); + it('should tolerate error src', fakeAsync(() => { + expect(getType(dl)).toBe('image'); + expect(context.comp.hasSrc).toBe(true); + // Manually dispatch error. + context.nzSrc = ''; + context.comp.imgError(); + tick(); + fixture.detectChanges(); + expect(getType(dl)).toBe('icon'); + expect(context.comp.hasSrc).toBe(false); + context.nzSrc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg=='; + tick(); + fixture.detectChanges(); + expect(context.comp.hasSrc).toBe(true); + expect(getType(dl)).toBe('image'); + tick(); + })); }); it('#nzIcon', () => { diff --git a/components/avatar/nz-avatar.component.ts b/components/avatar/nz-avatar.component.ts index 47b8579bc6c..b22f2a89bbe 100644 --- a/components/avatar/nz-avatar.component.ts +++ b/components/avatar/nz-avatar.component.ts @@ -103,6 +103,7 @@ export class NzAvatarComponent implements OnChanges { ngOnChanges(changes: SimpleChanges): void { this.hasText = !this.nzSrc && !!this.nzText; this.hasIcon = !this.nzSrc && !!this.nzIcon; + this.hasSrc = !!this.nzSrc; this.setClass().notifyCalc(); }