diff --git a/components/rate/rate.component.ts b/components/rate/rate.component.ts index b3d622c63d9..87f61b03580 100644 --- a/components/rate/rate.component.ts +++ b/components/rate/rate.component.ts @@ -130,7 +130,7 @@ export class NzRateComponent implements OnInit, ControlValueAccessor, OnChanges } this._value = input; - this.hasHalf = !Number.isInteger(input); + this.hasHalf = !Number.isInteger(input) && this.nzAllowHalf; this.hoverValue = Math.ceil(input); } diff --git a/components/rate/rate.spec.ts b/components/rate/rate.spec.ts index 28c96525e6d..a28632bd831 100644 --- a/components/rate/rate.spec.ts +++ b/components/rate/rate.spec.ts @@ -61,9 +61,22 @@ describe('rate', () => { expect(testComponent.modelChange).toHaveBeenCalledTimes(1); })); it('should allow half work', fakeAsync(() => { - testComponent.allowHalf = true; + testComponent.allowHalf = false; fixture.detectChanges(); expect(testComponent.value).toBe(0); + testComponent.value = 3.5; + fixture.detectChanges(); + flush(); + fixture.detectChanges(); + expect(rate.nativeElement.firstElementChild.children[3].classList).toContain('ant-rate-star-full'); + expect(rate.nativeElement.firstElementChild.children[4].classList).toContain('ant-rate-star-zero'); + flush(); + + testComponent.allowHalf = true; + testComponent.value = 0; + fixture.detectChanges(); + flush(); + fixture.detectChanges(); rate.nativeElement.firstElementChild.children[3].firstElementChild.children[1].click(); fixture.detectChanges(); flush();