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!
CodePudding user response:
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'),
});
CodePudding user response:
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.