import 'reflect-metadata'; import { StarRatingSelectorComponent, } from './star-rating-selector.component'; const initStarRatingSelectorComponent = () => new StarRatingSelectorComponent(); describe('isASelectedStar', () => { test('Returns false if there is no selected star rating set', () => { const starRatingSelectorComponent = initStarRatingSelectorComponent(); starRatingSelectorComponent.selectedStarRating = undefined; const result = starRatingSelectorComponent.isASelectedStar(3); expect(result).toBe(false); }); // tslint:disable-next-line test('Returns false if the selected star rating set but the supplied number is greater', () => { const starRatingSelectorComponent = initStarRatingSelectorComponent(); starRatingSelectorComponent.selectedStarRating = 3; const result = starRatingSelectorComponent.isASelectedStar(4); expect(result).toBe(false); }); // tslint:disable-next-line test('Returns true if the selected star rating set and the supplied number is the same', () => { const starRatingSelectorComponent = initStarRatingSelectorComponent(); starRatingSelectorComponent.selectedStarRating = 3; const result = starRatingSelectorComponent.isASelectedStar(3); expect(result).toBe(true); }); // tslint:disable-next-line test('Returns true if the selected star rating set and the supplied number is less', () => { const starRatingSelectorComponent = initStarRatingSelectorComponent(); starRatingSelectorComponent.selectedStarRating = 3; const result = starRatingSelectorComponent.isASelectedStar(2); expect(result).toBe(true); }); }); describe('selectRating', () => { test('Calls onSelectRating.emit with the supplied number', () => { const starRatingSelectorComponent = initStarRatingSelectorComponent(); starRatingSelectorComponent.onSelectRating.emit = jest.fn(); starRatingSelectorComponent.selectRating(5); expect(starRatingSelectorComponent.onSelectRating.emit) .toHaveBeenCalledWith(5); }); });