Files
piratepoet/mailpoet/tests/javascript/utilities/date.spec.ts
Rostislav Wolny 1d32461b3d Workaround for the issue with chai v5 and ES modules
I couldn't make it work with the Babel loader. There is a possible
solution using ts-node as a loader. I didn't want to install another
package, so I chose a different workaround.
mocha-env.mjs is processed as a module thanks to the suffix, and it
sets chai. expect globally, and then I updated tests to use the global expect.

Please see https://github.com/chaijs/chai/issues/1568
[MAILPOET-6008]
2024-06-19 12:12:59 +02:00

43 lines
1.2 KiB
TypeScript

import moment, { Moment } from 'moment';
import { MailPoetDate } from '../../../assets/js/src/date';
describe('MailPoetDate', () => {
describe('isInFuture', () => {
let now: Moment | undefined;
beforeEach(() => {
now = moment(Date.now());
});
it('Should work correctly for present', () => {
expect(MailPoetDate.isInFuture(now.toISOString(), now)).to.be.false;
});
it('Should work correctly for future dates', () => {
const tomorrow = now.clone().add(1, 'days').toISOString();
expect(
MailPoetDate.isInFuture(
now.clone().add(1, 'seconds').toISOString(),
now,
),
'1 second in future',
).to.be.true;
expect(MailPoetDate.isInFuture(tomorrow, now.valueOf())).to.be.true;
});
it('Should work correctly for past dates ', () => {
const yesterday = now.clone().add(-1, 'days');
expect(
MailPoetDate.isInFuture(
now.clone().add(-1, 'seconds').toISOString(),
now,
),
'1 second in the past',
).to.be.false;
expect(MailPoetDate.isInFuture(yesterday.toISOString(), now), 'yesterday')
.to.be.false;
});
});
});