Cypress: Cypress.moment.locale() not setting locale in a test

Created on 18 Dec 2018  路  6Comments  路  Source: cypress-io/cypress

Current behaviour:

Currently, we can not set locale in Cypress with the context of file using Cypress.moment.locale('fr')

Desired behaviour:

It should change the locale against Cypress.moment throughout the test

Steps to reproduce: (app code and test code)

Create new spec file and paste the following code

describe('test', () => {
  it('compare', () => {
    Cypress.moment.locale('fr');
    console.log('cypress', Cypress.moment().format('MMMM'));
  })
})

Versions

os -> macos mojave 10.14
cypress -> ^3.1.0

1锔忊儯 proposal 馃挕 enhancement

Most helpful comment

Would be good if we could set the locale to moment on Cypress!

All 6 comments

Meanwhile if you use this code it will work

describe('test', () => {
            it('compare', () => {
              moment.locale('fr');
              console.log('moment', .moment().format('MMMM'));
           })
       })

I have installed the moment library separately for working of this

moment.locale requires an import in addition to the standard moment import and has not been included in Cypress. Importing moment-with-locales.min.js would add 81.9 KB

@jennifer-shehane is there a reason that you guys intentionally choose to not add that 81.9KB?

Would be good if we could set the locale to moment on Cypress!

We just solved this with a single line in our support/index.js file:

Cypress.moment.locale('de');

No reason not to add this, just stating the facts of adding it. We're open to PRs for adding features like this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brian-mann picture brian-mann  路  3Comments

jennifer-shehane picture jennifer-shehane  路  3Comments

tahayk picture tahayk  路  3Comments

igorpavlov picture igorpavlov  路  3Comments

egucciar picture egucciar  路  3Comments