Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!