From 5826fc1d17569273e8cf81f6cb2356ecc9aec60e Mon Sep 17 00:00:00 2001 From: Wendell Date: Thu, 27 Jun 2019 20:39:30 +0800 Subject: [PATCH] fix(module:descriptions): fix warning without logger (#3663) --- components/descriptions/demo/border.ts | 2 +- .../descriptions/nz-descriptions.component.ts | 4 +- .../descriptions/nz-descriptions.spec.ts | 44 +++++++++---------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/components/descriptions/demo/border.ts b/components/descriptions/demo/border.ts index eaae3002dc..bdbd5cddc2 100644 --- a/components/descriptions/demo/border.ts +++ b/components/descriptions/demo/border.ts @@ -10,7 +10,7 @@ import { Component } from '@angular/core'; 2018-04-24 18:00:00 - + 2018-04-24 18:00:00 To 2019-04-24 18:00:00 diff --git a/components/descriptions/nz-descriptions.component.ts b/components/descriptions/nz-descriptions.component.ts index 2e394a645c..b6a782d244 100644 --- a/components/descriptions/nz-descriptions.component.ts +++ b/components/descriptions/nz-descriptions.component.ts @@ -27,7 +27,7 @@ import { import { fromEvent, merge, Subject } from 'rxjs'; import { auditTime, startWith, takeUntil } from 'rxjs/operators'; -import { responsiveMap, Breakpoint, InputBoolean } from 'ng-zorro-antd/core'; +import { responsiveMap, warn, Breakpoint, InputBoolean } from 'ng-zorro-antd/core'; import { NzDescriptionsItemRenderProps, NzDescriptionsSize } from './nz-descriptions-definitions'; import { NzDescriptionsItemComponent } from './nz-descriptions-item.component'; @@ -152,7 +152,7 @@ export class NzDescriptionsComponent implements OnChanges, OnDestroy, AfterConte // Warn user about that. if (width >= column) { if (width > column && isDevMode()) { - console.warn(`"nzColumn" is ${column} but we have row length ${width}`); + warn(`"nzColumn" is ${column} but we have row length ${width}`); } flushRow(); } diff --git a/components/descriptions/nz-descriptions.spec.ts b/components/descriptions/nz-descriptions.spec.ts index 5595454675..ad8f523294 100644 --- a/components/descriptions/nz-descriptions.spec.ts +++ b/components/descriptions/nz-descriptions.spec.ts @@ -6,6 +6,21 @@ import { NzDescriptionsModule } from './nz-descriptions.module'; // tslint:disable-next-line no-any declare const viewport: any; +@Component({ + template: ` + + + + + ` +}) +export class NzTestDescriptionsComponent { + bordered = false; + colspanArray: number[] = [1, 1, 1]; + column: number | { [key: string]: number } = 3; + title = 'Title'; +} + describe('nz descriptions', () => { let testComponent: NzTestDescriptionsComponent; let componentElement: HTMLElement; @@ -53,8 +68,8 @@ describe('nz descriptions', () => { rows = componentElement.querySelectorAll('.ant-descriptions-row'); expect(rows.length).toBe(3); expect(spyOnWarn).toHaveBeenCalledTimes(2); - expect(spyOnWarn).toHaveBeenCalledWith('"nzColumn" is 3 but we have row length 5'); - expect(spyOnWarn).toHaveBeenCalledWith('"nzColumn" is 3 but we have row length 6'); + expect(spyOnWarn).toHaveBeenCalledWith('[NG-ZORRO]:', '"nzColumn" is 3 but we have row length 5'); + expect(spyOnWarn).toHaveBeenCalledWith('[NG-ZORRO]:', '"nzColumn" is 3 but we have row length 6'); testComponent.column = 5; testComponent.colspanArray = [1, 2, 3]; @@ -62,7 +77,7 @@ describe('nz descriptions', () => { rows = componentElement.querySelectorAll('.ant-descriptions-row'); expect(rows.length).toBe(1); expect(spyOnWarn).toHaveBeenCalledTimes(4); - expect(spyOnWarn).toHaveBeenCalledWith('"nzColumn" is 5 but we have row length 6'); + expect(spyOnWarn).toHaveBeenCalledWith('[NG-ZORRO]:', '"nzColumn" is 5 but we have row length 6'); testComponent.colspanArray = [1, 2, 2]; fixture.detectChanges(); @@ -83,17 +98,17 @@ describe('nz descriptions', () => { viewport.set(1024, 1024); window.dispatchEvent(new Event('resize')); - fixture.autoDetectChanges(); + fixture.detectChanges(); tick(1000); - fixture.autoDetectChanges(); + fixture.detectChanges(); rows = componentElement.querySelectorAll('.ant-descriptions-row'); expect(rows.length).toBe(3); viewport.set(320, 320); window.dispatchEvent(new Event('resize')); - fixture.autoDetectChanges(); + fixture.detectChanges(); tick(1000); - fixture.autoDetectChanges(); + fixture.detectChanges(); rows = componentElement.querySelectorAll('.ant-descriptions-row'); expect(rows.length).toBe(7); @@ -102,18 +117,3 @@ describe('nz descriptions', () => { })); }); }); - -@Component({ - template: ` - - - - - ` -}) -export class NzTestDescriptionsComponent { - bordered = false; - colspanArray: number[] = [1, 1, 1]; - column: number | { [key: string]: number } = 3; - title = 'Title'; -}