Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

formatDuration.test.ts 1.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  1. import { formatDuration } from '../../src/util/formatDuration';
  2. describe('formatDuration', () => {
  3. it('should format seconds only', () => {
  4. expect(formatDuration(45)).toBe('45s');
  5. expect(formatDuration(0)).toBe('0s');
  6. expect(formatDuration(59)).toBe('59s');
  7. });
  8. it('should format minutes and seconds', () => {
  9. expect(formatDuration(60)).toBe('1m 0s');
  10. expect(formatDuration(65)).toBe('1m 5s');
  11. expect(formatDuration(119)).toBe('1m 59s');
  12. expect(formatDuration(600)).toBe('10m 0s');
  13. });
  14. it('should format hours, minutes, and seconds', () => {
  15. expect(formatDuration(3600)).toBe('1h 0m 0s');
  16. expect(formatDuration(3661)).toBe('1h 1m 1s');
  17. expect(formatDuration(7382)).toBe('2h 3m 2s');
  18. });
  19. it('should handle edge cases correctly', () => {
  20. // Test with decimal values - should round down
  21. expect(formatDuration(45.9)).toBe('45s');
  22. // Test with very large values
  23. expect(formatDuration(86400)).toBe('24h 0m 0s'); // 1 day
  24. expect(formatDuration(90061)).toBe('25h 1m 1s'); // 1 day, 1 hour, 1 minute, 1 second
  25. // Test with string numbers (TypeScript should handle this implicitly)
  26. expect(formatDuration(Number('120'))).toBe('2m 0s');
  27. });
  28. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...