【问题标题】:Cypress.moment using localeCypress.moment 使用语言环境
【发布时间】:2018-12-18 09:14:40
【问题描述】:

我正在尝试使用 Cypress.moment 来比较日期。目标网站是法语所以日期格式。

因此,我打算使用moment.js的方法来切换fr locale。

Cypress.moment.locale('fr')

我应该能够像他们在 cypress 文档中所说的那样做到这一点:

Cypress 自动包含 moment.js 并将其公开为 Cypress.moment https://docs.cypress.io/api/utilities/moment.html#Syntax

那么,

const todaysDate = Cypress.moment().format('Do')
const currentMonth = Cypress.moment().format('MMMM')

cy.get('.date__title').should('contain', todaysDate)
cy.get('.c-title').should('contain', currentMonth)

但断言失败,因为 cypress 拒绝考虑 fr 语言环境。例如,它不断将“décembre”与“december”进行比较。这显然失败了。

我做错了什么?

【问题讨论】:

    标签: automated-tests locale cypress


    【解决方案1】:

    same aforementioned thread 中,最近出现了一个有效的答案:

    把这个放到support/index.js:

    Cypress.moment.locale('de');
    

    它在我的项目中表现出色

    【讨论】:

      【解决方案2】:

      不幸的是,在撰写本文时,我认为 Cypress.moment.locale() 无法做到这一点,正如您可以在他们的 git 存储库中的 this 问题中看到的那样。

      正如那里评论的那样,moment.locale 需要在标准 moment 导入之外进行导入,该导入是 moment-with-locales.min.js,并且尚未包含在赛普拉斯中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-06-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-22
        • 1970-01-01
        相关资源
        最近更新 更多