UNPKG

@schukai/monster

Version:

Monster is a simple library for creating fast, robust and lightweight websites.

34 lines (25 loc) 1.29 kB
import {expect} from "chai" import {formatTimeAgo} from "../../../source/i18n/time-ago.mjs"; describe('formatTimeAgo', () => { it('returns "just now" for times less than a second ago', () => { const now = new Date(); expect(formatTimeAgo(now, 'en')).to.equal('just now'); }); it('returns "in 1 second" for one second in the future', () => { const oneSecondFuture = new Date(Date.now() + 1000); expect(formatTimeAgo(oneSecondFuture, 'en')).to.equal('in 1 second'); }); it('returns "1 second ago" for one second in the past', () => { const oneSecondPast = new Date(Date.now() - 1000); expect(formatTimeAgo(oneSecondPast, 'en')).to.equal('1 second ago'); }); it('returns "in 1 minute, 30 seconds" for 90 seconds in the future', () => { const ninetySecondsFuture = new Date(Date.now() + 90000); expect(formatTimeAgo(ninetySecondsFuture, 'en')).to.equal('in 1 minute and 30 seconds'); }); it('returns "1 minute, 30 seconds ago" for 90 seconds in the past', () => { const ninetySecondsPast = new Date(Date.now() - 90000); expect(formatTimeAgo(ninetySecondsPast, 'en')).to.equal('1 minute and 30 seconds ago'); }); // Weitere Tests können hinzugefügt werden });