aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/helpers/reading-time.test.ts
blob: 24181a6acfe196a97570e1f5dea67670cb23cddd (plain)
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
import { describe, it } from '@jest/globals';
import { getReadingTimeFrom } from './reading-time';

describe('reading-time', () => {
  it('can transform a words count into a reading time in minutes', () => {
    const wordsCount = 250;

    // With the default settings, 250 words should be rounded to one minute.
    expect(getReadingTimeFrom(wordsCount).inMinutes()).toBe(1);
  });

  it('can transform a words count into a reading time in minutes and seconds', () => {
    const wordsCount = 1200;
    const readingTime = getReadingTimeFrom(wordsCount).inMinutesAndSeconds();

    expect(readingTime.minutes).toBeGreaterThan(1);
    expect(readingTime.seconds).toBeGreaterThan(0);
  });

  it('can use a custom words per minute setting', () => {
    const wordsCount = 100;
    const wordsPerMinute = 100;
    const readingTime = getReadingTimeFrom(
      wordsCount,
      wordsPerMinute
    ).inMinutesAndSeconds();

    expect(readingTime.minutes).toBe(1);
    expect(readingTime.seconds).toBe(0);
  });
});