|
2 | 2 | * Unit tests for lib/util.ts |
3 | 3 | */ |
4 | 4 | import { describe, it, expect } from 'vitest'; |
5 | | -import { assertSupportedEasingFunction, $ } from '../lib/util'; |
| 5 | +import { assertIntegerCap, assertSupportedEasingFunction, $ } from '../lib/util'; |
| 6 | + |
| 7 | +describe('assertIntegerCap', () => { |
| 8 | + it('accepts value equal to min', () => { |
| 9 | + expect(() => assertIntegerCap('x', 0, 0)).not.toThrow(); |
| 10 | + expect(() => assertIntegerCap('x', 1, 1)).not.toThrow(); |
| 11 | + }); |
| 12 | + |
| 13 | + it('accepts value above min', () => { |
| 14 | + expect(() => assertIntegerCap('x', 5, 1)).not.toThrow(); |
| 15 | + expect(() => assertIntegerCap('x', 100, 0)).not.toThrow(); |
| 16 | + }); |
| 17 | + |
| 18 | + it('throws for value below min', () => { |
| 19 | + expect(() => assertIntegerCap('ms:windowSwitchRetries', 0, 1)).toThrow('must be an integer >= 1'); |
| 20 | + expect(() => assertIntegerCap('ms:windowSwitchInterval', -1, 0)).toThrow('must be an integer >= 0'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('throws for floats', () => { |
| 24 | + expect(() => assertIntegerCap('x', 1.5, 1)).toThrow('must be an integer'); |
| 25 | + expect(() => assertIntegerCap('x', 0.1, 0)).toThrow('must be an integer'); |
| 26 | + }); |
| 27 | + |
| 28 | + it('includes cap name and received value in error message', () => { |
| 29 | + expect(() => assertIntegerCap('ms:windowSwitchRetries', -3, 1)).toThrow("'ms:windowSwitchRetries'"); |
| 30 | + expect(() => assertIntegerCap('ms:windowSwitchRetries', -3, 1)).toThrow('got -3'); |
| 31 | + }); |
| 32 | +}); |
6 | 33 |
|
7 | 34 | describe('assertSupportedEasingFunction', () => { |
8 | 35 | it.each(['linear', 'ease', 'ease-in', 'ease-out', 'ease-in-out'])( |
|
0 commit comments