on-number.test.ts 632 B

1234567891011121314151617181920212223
  1. import { describe, expect, it, vi } from 'vitest';
  2. import { onNumber } from '@/utils/onNumber';
  3. describe('onNumber', () => {
  4. it('forwards numeric values, including zero and negatives', () => {
  5. const apply = vi.fn();
  6. const handler = onNumber(apply);
  7. handler(8443);
  8. handler(0);
  9. handler(-1);
  10. expect(apply.mock.calls).toEqual([[8443], [0], [-1]]);
  11. });
  12. it('ignores cleared events instead of writing a synthetic value', () => {
  13. const apply = vi.fn();
  14. const handler = onNumber(apply);
  15. handler(null);
  16. handler(undefined);
  17. handler(NaN);
  18. expect(apply).not.toHaveBeenCalled();
  19. });
  20. });