Bug 1395773 - Fix intermittent browser_datetime_datepicker test when crossing months, r=mconley
MozReview-Commit-ID: Dhs0KX9UUOC
--- a/toolkit/content/tests/browser/browser_datetime_datepicker.js
+++ b/toolkit/content/tests/browser/browser_datetime_datepicker.js
@@ -4,16 +4,17 @@
"use strict";
const MONTH_YEAR = ".month-year",
DAYS_VIEW = ".days-view",
BTN_PREV_MONTH = ".prev",
BTN_NEXT_MONTH = ".next";
const DATE_FORMAT = new Intl.DateTimeFormat("en-US", { year: "numeric", month: "long", timeZone: "UTC" }).format;
+const DATE_FORMAT_LOCAL = new Intl.DateTimeFormat("en-US", { year: "numeric", month: "long" }).format;
// Create a list of abbreviations for calendar class names
const W = "weekend",
O = "outside",
S = "selection",
R = "out-of-range",
T = "today",
P = "off-step";
@@ -49,17 +50,21 @@ registerCleanupFunction(() => {
/**
* Test that date picker opens to today's date when input field is blank
*/
add_task(async function test_datepicker_today() {
const date = new Date();
await helper.openPicker("data:text/html, <input type='date'>");
- Assert.equal(helper.getElement(MONTH_YEAR).textContent, DATE_FORMAT(date));
+ if (date.getMonth() === new Date().getMonth()) {
+ Assert.equal(helper.getElement(MONTH_YEAR).textContent, DATE_FORMAT_LOCAL(date));
+ } else {
+ Assert.ok(true, "Skipping datepicker today test if month changes when opening picker.");
+ }
await helper.tearDown();
});
/**
* Test that date picker opens to the correct month, with calendar days
* displayed correctly, given a date value is set.
*/