Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
Struggling to have DayJs available for all tests in cypress

I'm currently starting a new Cypress project, the application to test is quite "calendar centered" and I'll have to play a lot with dates.

My issue is I can't get DayJs available for the whole project without having to import it in every spec files.

For instance, in a test.spec.ts, this is working

import dayjs = require('dayjs');
    
describe('Some suite', () => {       
   it('Some Test', () => {
      // some stuff
      const myDate = dayjs('11-11-2022', 'dd-MM-YYYY' );
      // other stuff
   })
})

But when I do this in support/index.ts

import dayjs = require('dayjs')
    
declare namespace Cypress {        
    interface Cypress {
        dayjs: dayjs.Dayjs;
    }
}

and then this in my spec

describe('Some suite', () => {       
    it('Some Test', () => {
       // some stuff
       const myDate = Cypress.dayjs('11-11-2022', 'dd-MM-YYYY' );
       // other stuff
    })
})

it says

Cypress.dayjs is not a function

Any idea on how I could get this work? Thanks for the help

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In /cypress/support/index.ts, add dayjs to the global Cypress (just like momentjs used to be included).

/cypress/support/index.ts

const dayjs = require('dayjs')

declare namespace Cypress {        
  interface Cypress {
    dayjs: dayjs.Dayjs;
  }
}

Cypress.dayjs = dayjs

Now const myDate = Cypress.dayjs('11-11-2022', 'dd-MM-YYYY') should work.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda