'Cypress - replaceing moment() with dayjs
I'm having problems with the locale when going from the deprecated Moment to DayJS in Cypress.
The original Moment() usage:
public moment(): Moment {
const moment = Cypress.moment();
moment.locale("nb-NO");
return moment;
}
const in2Months = moment().add(2, "months");
This worked fine, and for instance "March" was replaced by "Mars".
However, when trying to use it the same way with days.js, the locale isn't changed:
public day() {
return dayjs().locale('nb-NO');
}
const in2Months = page.day().add(2, "months");
The result here is still "March". I've tried using just 'no' for the locale, with the same result.
What am I missing here?
UPDATE: As per the below answer:
import dayjs from "dayjs";
import 'dayjs/locale/nb'
const in2Months = dayjs().locale('nb').add(2, 'Month');
cy.log(in2monthstoString());
RESULT: Mon, 28 Mar 2022 12:39:29 GMT
Not local format.
Also, trying any variation of .month() I can find allways results in the number of the month. I cannot get the name.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
