mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-27 20:03:25 +01:00
Fix use of Date.now() in test
This commit is contained in:
@@ -284,9 +284,18 @@ describe('DonationsCardForm', () => {
|
||||
});
|
||||
|
||||
describe('parseCardExpiration', () => {
|
||||
const now = new Date('2025-02-03T04:05:06.078Z');
|
||||
|
||||
const currMonth = 2;
|
||||
const currYear = 2025;
|
||||
const lastMonth = 1;
|
||||
const lastYear = 2024;
|
||||
const nextMonth = 3;
|
||||
const nextYear = 2026;
|
||||
|
||||
function checkValid(input: string, month: string, year: string) {
|
||||
it(`${JSON.stringify(input)} -> ${month}/${year} (valid)`, () => {
|
||||
assert.deepEqual(parseCardExpiration(input), { month, year });
|
||||
assert.deepEqual(parseCardExpiration(input, now), { month, year });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -297,7 +306,7 @@ describe('DonationsCardForm', () => {
|
||||
year: string
|
||||
) {
|
||||
it(`${JSON.stringify(input)} -> ${error} (error with values)`, () => {
|
||||
assert.deepEqual(parseCardExpiration(input), {
|
||||
assert.deepEqual(parseCardExpiration(input, now), {
|
||||
error,
|
||||
month,
|
||||
year,
|
||||
@@ -307,19 +316,10 @@ describe('DonationsCardForm', () => {
|
||||
|
||||
function checkError(input: string, error: CardExpirationError) {
|
||||
it(`${JSON.stringify(input)} -> ${error} (error)`, () => {
|
||||
assert.deepEqual(parseCardExpiration(input), { error });
|
||||
assert.deepEqual(parseCardExpiration(input, now), { error });
|
||||
});
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
|
||||
const currMonth = now.getMonth() + 1;
|
||||
const currYear = now.getFullYear();
|
||||
const lastMonth = currMonth - 1;
|
||||
const lastYear = currYear - 1;
|
||||
const nextMonth = currMonth + 1;
|
||||
const nextYear = currYear + 1;
|
||||
|
||||
const mm = (month: number) => String(month).padStart(2, '0');
|
||||
const yy = (year: number) => String(year - 2000).padStart(2, '0');
|
||||
const yyyy = (year: number) => String(year).padStart(4, '0');
|
||||
|
||||
Reference in New Issue
Block a user