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

172
Visualizações
Testcase to check if multiple files of specific pattern are present

Want to validate if multiple files with filenames in a specific pattern are created by a function. The test case I have written is

describe('Sitemap', () => {
       it('it should create XML sitemap', () => {
              let language='hindi'
              return sitemapContainer.createSitemap(language).then(() => {
                   expect(fs.existsSync(`sos/sos_${language}*.xml`)).to.be.true
              });       
        })
})

but it fails. Which function should I use in place of fs.existsSync so that pattern could be matched . Some example files are sos_hindi_1.xml , sos_hindi_2.xml , sos_hindi_3.xml .

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

0

existsSync looks for a single file, but you can think out of the box and come with a different approach.

You can instead read the entire folder so that you have a list of files, and then do your manipulations.

expect(fs.readdirSync('sos/').some(file => /* your condition */)).to.be.true

If at least one file matches your condition, it will return true

Possible solution

With a regex, you can do something like that

let lan = "hindi";
var reg = new RegExp(`sos_${lan}_\\S\.xml`, 'g');
expect(fs.readdirSync('sos/').some(file => file.match(reg))).to.be.true
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