Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions __tests__/formatter-value-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import '@testing-library/jest-dom'
import { render, screen } from '@testing-library/react'
import React from 'react'
import TimeAgo from '../src'

it('should handle null formatter gracefully', () => {
render(<TimeAgo date={Date.now() - 1000 * 60} formatter={null} />)
expect(screen.getByText('1 minute ago')).toBeInTheDocument()
})

it('should handle empty function formatter', () => {
render(<TimeAgo date={Date.now() - 2000 * 60 * 60} formatter={() => {}} />)
expect(screen.getByText('2 hours ago')).toBeInTheDocument()
})

it('should handle formatter throwing an error', () => {
render(
<TimeAgo
date={Date.now() - 2000 * 60}
formatter={() => {
throw new Error('Faulty formatter')
}}
/>,
)
expect(screen.getByText('2 minutes ago')).toBeInTheDocument()
})