Running tests - Web Dev 101 Fundaments part 4


#1

https://www.theodinproject.com/courses/web-development-101/lessons/fundamentals-part-4?ref=lnav

I’m to the point in this lesson of doing the exercises at the end. I’m not confused about writing the JS in the exercises. I’m confused about jasmine and running tests. Was this covered before and I missed it completely? Is jasmine something that I should have installed before now? Where do I find out how to do that?

Thanks in advance.


#2

Hi @mandimh

The readme in the github repo does contain instructions of how to get setup

If you have any problems getting setup let us know :slight_smile:


#3

Thank you! I’ll go through that. I was reading the READMe file in the “hello world” exercise since that was the first assigned exercise. I’ll come back and comment here if I’m still lost after going through that file.

I really appreciate your help.


#4

Just to allay any worries, Jasmine was not introduced prior to the JS Fundamentals exercises. The focus is really to flex your Javascript and check your answers against tests, without worrying about writing the tests themselves (for now). @codyloyd can probably add more insight, but otherwise, carry on!


#5

hello I set up the helloWorld.js
const helloWorld = function() {
return ‘Hello, World!’
}

module.exports = helloWorld()
but the string is still empty: what can i do?


#6

You need to export helloWorld not helloWorld() which will run the function and export the result of that.


#7

Hi,

At first I tried the reverseString exercise with a for loop. It worked in jsfiddle and passed each jasmine test individually (with the others disabled with xit), but failed when I enabled all 3 tests. Why is this? Here is my reverseString with for:

let reversedString = '';
const reverseString = function(string) { 
for (let i=string.length-1; i >= 0; i--) {
        reversedString += string[i];  
        }
        return reversedString;
}

module.exports = reverseString 

With the for loop, enabling all 3 tests generated errors such as Expected '!cba !321ereht olleh' to equal 'ereht olleh'.

I was able to make reverseString work by combining, split(), reverse() and join(), but I would like to understand what happened with my for loop.

Thanks very much!


#8

You declare reversedString outside of the function so it’s creating a global variable which is being preserved between the tests. Move the top line to inside the function.


#9

Thanks very much! This isn’t the first time scope has tripped me up