|
| 1 | +import dateConverter from '../src/dateConverter' |
1 | 2 | import NepaliDate from '../src/NepaliDate' |
2 | 3 | import { ValidationError } from '../src/validators' |
3 | 4 |
|
@@ -741,3 +742,48 @@ describe('NepaliDate with Time feature: set methods', () => { |
741 | 742 | }) |
742 | 743 | }) |
743 | 744 | }) |
| 745 | + |
| 746 | +describe('NepaliDate.getDaysOfMonth', () => { |
| 747 | + it('should return the correct number of days for a valid year and month', () => { |
| 748 | + const days = NepaliDate.getDaysOfMonth(2081, 8) |
| 749 | + expect(days).toBe(29) |
| 750 | + }) |
| 751 | + |
| 752 | + it('should return the correct number of days for a year 2000 and month 0', () => { |
| 753 | + const days = NepaliDate.getDaysOfMonth(2000, 0) |
| 754 | + expect(days).toBe(30) |
| 755 | + }) |
| 756 | + |
| 757 | + it('should return the correct number of days for a year 2099 and month 11', () => { |
| 758 | + const days = NepaliDate.getDaysOfMonth(2099, 11) |
| 759 | + expect(days).toBe(30) |
| 760 | + }) |
| 761 | + |
| 762 | + it('should throw an error if the year is below the valid range', () => { |
| 763 | + const invalidYear = dateConverter.npMinYear() - 1 |
| 764 | + expect(() => NepaliDate.getDaysOfMonth(invalidYear, 0)).toThrow( |
| 765 | + 'Year out of range' |
| 766 | + ) |
| 767 | + }) |
| 768 | + |
| 769 | + it('should throw an error if the year is above the valid range', () => { |
| 770 | + const invalidYear = dateConverter.npMaxYear() + 1 |
| 771 | + expect(() => NepaliDate.getDaysOfMonth(invalidYear, 0)).toThrow( |
| 772 | + 'Year out of range' |
| 773 | + ) |
| 774 | + }) |
| 775 | + |
| 776 | + it('should throw an error if the month is below 0', () => { |
| 777 | + const validYear = dateConverter.npMinYear() |
| 778 | + expect(() => NepaliDate.getDaysOfMonth(validYear, -1)).toThrow( |
| 779 | + 'Month out of range' |
| 780 | + ) |
| 781 | + }) |
| 782 | + |
| 783 | + it('should throw an error if the month is greater than 11', () => { |
| 784 | + const validYear = dateConverter.npMinYear() |
| 785 | + expect(() => NepaliDate.getDaysOfMonth(validYear, 12)).toThrow( |
| 786 | + 'Month out of range' |
| 787 | + ) |
| 788 | + }) |
| 789 | +}) |
0 commit comments