getSpeed.test.ts 560 B

123456789101112131415161718
  1. import { describe, expect, it } from 'vitest'
  2. import getSpeed from './getSpeed.ts'
  3. describe('getSpeed', () => {
  4. it('should calculate the speed given a fileProgress object', () => {
  5. const dateNow = new Date()
  6. const date5SecondsAgo = new Date(dateNow.getTime() - 5 * 1000)
  7. const fileProgress = {
  8. bytesUploaded: 1024,
  9. uploadStarted: date5SecondsAgo.getTime(),
  10. progress: 0,
  11. uploadComplete: false,
  12. percentage: 0,
  13. bytesTotal: 0,
  14. }
  15. expect(Math.round(getSpeed(fileProgress))).toEqual(Math.round(205))
  16. })
  17. })