Software DevelopmentBeginner 1 to 2 hours

Write Unit Tests for Utility Functions

Write a comprehensive test suite for a complex date-formatting utility.

The Scenario

A teammate wrote a `formatRelativeDate(dateString)` function that returns "just now", "5 minutes ago", "yesterday", etc. However, it sometimes breaks on leap years and cross-timezone inputs. You need to write the tests to prove it.

The Brief

Write a comprehensive Jest or Mocha test suite for the `formatRelativeDate` function. Focus on testing the edge cases (leap years, different timezones, invalid inputs) rather than just the happy path.

Deliverables

  • The complete test suite code (e.g., `dateFormatter.test.js`)
  • A short explanation of why it is important to mock the system clock (`Date.now()`) when testing time-relative functions

Submission Guidance

Assume the function exists and you are just writing the tests. A good test suite should act as documentation for the function’s expected behavior.

Submit Your Work

Your submission is graded against the rubric on the right. If you pass, you get a public Badge URL you can share on LinkedIn. There is no draft save, so work offline first and paste your finished response here.

This appears on your public Badge.

0/20000 charactersMarkdown supported

One per line or comma separated. Up to 5 links.

By submitting, you agree your submission text, name, and evaluation will appear on a public Badge URL.