Complete the helloWorld,repeatString and reverseString exercices with jasmine tests

This commit is contained in:
othmane 2019-02-16 21:50:47 +01:00
parent b2e42072de
commit ee8204f99d
6 changed files with 40 additions and 11 deletions

View File

@ -1,5 +1,5 @@
const helloWorld = function() {
return ''
return 'Hello, World!'
}
module.exports = helloWorld

View File

@ -1,5 +1,13 @@
const repeatString = function() {
const repeatString = function(repeat,j) {
if (j<0){
return 'ERROR';
}else{
var str = '';
for (var i=0; i<j; i++){
str=str+repeat;
}
return str;
}
}
module.exports = repeatString

View File

@ -4,16 +4,16 @@ describe('repeatString', function() {
it('repeats the string', function() {
expect(repeatString('hey', 3)).toEqual('heyheyhey');
});
xit('repeats the string many times', function() {
it('repeats the string many times', function() {
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
});
xit('repeats the string 1 times', function() {
it('repeats the string 1 times', function() {
expect(repeatString('hey', 1)).toEqual('hey');
});
xit('repeats the string 0 times', function() {
it('repeats the string 0 times', function() {
expect(repeatString('hey', 0)).toEqual('');
});
xit('returns ERROR with negative numbers', function() {
it('returns ERROR with negative numbers', function() {
expect(repeatString('hey', -1)).toEqual('ERROR');
});
});

View File

@ -1,5 +1,15 @@
const reverseString = function() {
const reverseString = function(str) {
let splitString = str.split("");
let reverseArray = splitString.reverse();
let joinArray = reverseArray.join("");
return joinArray;
}
module.exports = reverseString

View File

@ -5,7 +5,7 @@ describe('reverseString', function() {
expect(reverseString('hello')).toEqual('olleh');
});
xit('reverses multiple words', function() {
it('reverses multiple words', function() {
expect(reverseString('hello there')).toEqual('ereht olleh')
})

11
spec/support/jasmine.json Normal file
View File

@ -0,0 +1,11 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": true
}