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

119
Vistas
Issues incrementing characters in a string (Javascript)

I have this code:

function shift(str) { let newStr = [];

    for (let i = 0; i < str.length; i++) { 
    newStr[i] = String.fromCharCode(str[i].charCodeAt() + 1 //numbers > 1 returns a successful unit test); 
}                                  
    newStr = newStr.join('');

    return newStr; 
}

console.log(shift('pie')); // returns qjf

module.exports = shift;

When I console.log my function it properly returns the expected string of qjf, however, when I try to run tests with Jest:


test('pie returns qjf', () => [ 
    expect(shift('pie)).toBe('qjf),
 ]);

Running tests returns: "test functions can only return Promise or undefined. Returned value: Array [undefined,]". Not sure what I'm doing wrong, thanks for any help!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You are using square brackets instead of curly brackets in the test function. This should work:

test('pie returns qjf', () => { 
    expect(shift('pie')).toBe('qjf'),
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

Your test function is wrapped in [] instead of {}. It also looks like you're missing a single quote in the shift() and tobe() functions parameters.

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