Skip to content

Commit

Permalink
fix(module:avatar): tolerate error src (#2008)
Browse files Browse the repository at this point in the history
* fix(module:avatar): tolerate error src

* fix lint
  • Loading branch information
wendzhue authored and hsuanxyz committed Aug 19, 2018
1 parent fb3daa1 commit d55cdf2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions components/avatar/avatar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
1 change: 1 addition & 0 deletions components/avatar/nz-avatar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit d55cdf2

Please sign in to comment.