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

120
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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