Project: Testing 1-2-3
Introduction
Let's practice! This testing thing really is not that difficult, but it is quite new. The only way to get comfortable with it is to spend some time doing it.
Assignment
Write tests for the following functions, and then make the tests pass!
capitalize(string)
takes a string and returns that string with the first character capitalized.reverseString(string)
takes a string and returns it reversed.A
calculator
object that contains the basic operations:add
,subtract
,divide
, andmultiply
.Caesar Cipher. Read about it on this website
Don’t forget to test wrapping from
z
toa
.Don’t forget to test keeping the same case.
Don't forget to test punctuation!
For this one, you may want to split the final function into a few smaller functions. One concept of Testing is that you don't need to explicitly test every function you write... Just the public ones. So in this case you only need tests for the final
caesar()
function. If it works as expected you can rest assured that your smaller helper functions are doing what they're supposed to.
Array Analysis. Write a function that takes an array of numbers and returns an object with the following properties:
average
,min
,max
, andlength
.
Using ES6 import statements with Jest
By default, the current version of Jest will not recognize ES6 import statements. In order for you to be able to use ES6 modules for this project you may do the following:
Install the @babel/preset-env package
Create a .babelrc file in the project's root with the following lines of code:
This will allow you to use import statements. Note that in the Jest docs a similar instruction is laid out here.
Last updated