time-utils-test.js 435 B

123456789101112131415161718
  1. import { timer } from '../time-utils';
  2. describe('timer', () => {
  3. it('records how long a function takes to execute', () => {
  4. const add100k = (number) => {
  5. for (let i = 0; i < 100000; i += 1) {
  6. number += 1;
  7. }
  8. return number;
  9. };
  10. const timedFn = timer(add100k);
  11. const result = timedFn(70);
  12. expect(result).toEqual(100070);
  13. expect(Number.isInteger(timedFn.time)).toBeTruthy();
  14. });
  15. });