|
1 | 1 | import { describe, expect, it } from 'vitest' |
2 | 2 | import { composeVisitors, transform } from 'lightningcss' |
3 | 3 | import pxtorem from '../src/index' |
4 | | -import { validatePositiveInteger } from '../src/utils/errorHandler' |
| 4 | +import { validatePositiveInteger, validateIsNumber } from '../src/utils/errorHandler' |
5 | 5 |
|
6 | 6 | describe('pxtorem plugin', () => { |
7 | 7 | it('should convert pixel to rem using default configuration', () => { |
@@ -251,24 +251,33 @@ describe('pxtorem plugin', () => { |
251 | 251 | }) |
252 | 252 | }) |
253 | 253 |
|
254 | | -describe('validatePositiveInteger', () => { |
255 | | - it('should throw error for undefined value', () => { |
256 | | - expect(() => validatePositiveInteger(undefined, 'rootValue')).toThrowError('Invalid rootValue: must be a valid number.') |
257 | | - }) |
258 | | - |
259 | | - it('should throw error for NaN value', () => { |
260 | | - expect(() => validatePositiveInteger(NaN, 'rootValue')).toThrowError('Invalid rootValue: must be a valid number.') |
261 | | - }) |
262 | | - |
| 254 | +describe('validate errors', () => { |
263 | 255 | it('should throw error for negative value', () => { |
264 | 256 | expect(() => validatePositiveInteger(-1, 'rootValue')).toThrowError('Invalid rootValue: must not be negative.') |
265 | 257 | }) |
266 | 258 |
|
267 | 259 | it('should throw error for decimal value', () => { |
268 | | - expect(() => validatePositiveInteger(1.5, 'rootValue')).toThrowError('Invalid rootValue: must not be a decimal.') |
| 260 | + expect(() => validatePositiveInteger(1.5, 'unitPrecision')).toThrowError('Invalid unitPrecision: must not be a decimal.') |
269 | 261 | }) |
270 | 262 |
|
271 | 263 | it('should pass for valid integer value', () => { |
272 | | - expect(() => validatePositiveInteger(1, 'rootValue')).not.toThrow() |
| 264 | + expect(() => validatePositiveInteger(1, 'minValue')).not.toThrow() |
| 265 | + }) |
| 266 | + |
| 267 | + it('should throw error for non-number value', () => { |
| 268 | + // @ts-expect-error |
| 269 | + expect(() => validateIsNumber('10', 'rootValue')).toThrowError('Invalid rootValue: must be a valid number.') |
| 270 | + }) |
| 271 | + |
| 272 | + it('should pass for valid number value', () => { |
| 273 | + expect(() => validateIsNumber(1, 'unitPrecision')).not.toThrow() |
| 274 | + }) |
| 275 | + |
| 276 | + it('should pass for valid negative number value', () => { |
| 277 | + expect(() => validateIsNumber(-10, 'rootValue')).not.toThrow() |
| 278 | + }) |
| 279 | + |
| 280 | + it('should pass for valid float number value', () => { |
| 281 | + expect(() => validateIsNumber(10.50, 'minValue')).not.toThrow() |
273 | 282 | }) |
274 | 283 | }) |
0 commit comments