Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda