Unit Testing
To view lecture notes for this course, please consult the github-pages.
Instructions for Unit Exercises: 1. Go to unit folder cd unit
2. Open program.test.js and go to each TODO block. 3. Complete each todo block by adding unit tests. 4. Please run the following script to npm run unit:test
in order to do the unit test exercises
1. Unit Test the Map Function:
For a typical unit test I usually create 2 variables one named actual and another named expect
For assert.equal(actual, expected, 'My message here')
if actual and expected are equal then the unit test will pass.
The map function behaves in the following manner
This will return the following structure
Add variables actual and expected to this first unit test. The equal method expects to get single property/value in order to pass 1 === 1 or "Mike" === "Mike" The deepEqual method does a deep property check like this [1,2,3] === [1,2,3]
2. Unit Test the Filter Function.
The filter function behaves in the following manner
This will return the following structure [4, 5]
Either choose assert.equal
or assert.deepEqual
but remember deepEqual does a deep check with arrays but equal checks properties.
3. Unit Test the concatAll Function.
The concatAll function behaves in the following manner
This will return the following structure [1,2,3,4,5,6,7,8,9,10]
Write a Unit Test using the same format as previous 2 exercises.
4. Unit Test the concatMap Function.
The concatMap function behaves in the following manner
This will return the following structure ["One", "Two", "Three", "Four", "Five", "Six"]
Last updated