i got task to do, as I'm new in the academy.
I have a function, which is working, but during my test, it is allways saying: ● Test if it is right
ReferenceError: splitString is not defined
13 | 'Test if it is right',
14 | (fullName, splitString) => {
> 15 | expect(testSamoUloha(fullName)).toBe(splitString);
| ^
16 | }
17 | );
18 |
My question is,what parameter should I put into toBe(function).
Here is my test :
const testSamoUloha = require('../samostatnaUloha.js');
test("Should return a full name, where last name is anonymized by *", () => {
expect(testSamoUloha(fullName)).toBe('string');
})
test.each([["Richard Tezbir","Richard T*****"],
["Richard Tezbir","Richard T*****"],
["Slavomir Slovenkai","Slavomir S********"],
["Marek Mihok","Marek M****"],
["Maros Lukac","Maros L****"],
["Bernadet Molnarova","Bernadet M********"]])(
'Test if it is right',
(fullName, splitString) => {
expect(testSamoUloha(fullName)).toBe(splitString);
}
);
All others possibilities I have tried to put into toBe, it was saying (variable) is not a function. And here is my function:
const fullName = "Jozko Baci";
function testSamoUloha(fullName) {
var splitString = fullName.split(' ');
var tempString = '';
for (var i = 0; i < splitString[1].length; i++) {
if (i > 0) {
tempString += '*';
tempString += splitString[1][i];
}
}
return splitString[0] + ' ' + tempString;
}
testSamoUloha(fullName);
module.exports = testSamoUloha;
How could I get this done ?
Aucun commentaire:
Enregistrer un commentaire