Lab 7
Complete the Github classroom assignment Opens in a new window.
This is an individual assignment.
- Clone the assignment to your local environment
- Install mocha & chai via npm
Write five tests. The names and locations of your tests files are described in the package.json file under the individual test scripts. In order to pass the tests on Github, your file names will need to align with those listed in the package.json file.
(You do not have to run the individual tests on your local - as you can see, there is a script called test that will run all tests if they're in the correct folder for that sort of thing. Also, it's not relevant what order the tests run.)
For each test:
- import the
expect
assertion library, - import the exported function (or array, or whatever) that you want to test
- create a test suite that describes what you're testing
- create a test case that describes what your test is testing for
- Your first test should import the
studentCheck
function fromdoesStudentDuplicateExist.test.js
. Test the result of thestudentCheck
function to ensure that it is true that there are no duplicates in the students array. - Your next test should import the
stripHTML
function fromstripHTML.js
. Test the assertion that the function should remove HTML tags from a string. Provide a string containing HTML tags (including opening and closing tags, self-closing tags, and attributes) to the function, and expect the result to be a string, and to be equal to whatever text is in the provided string. Your third test should import the
aroc
function fromalphabetize.js
. The function should order an array alphabetically, regardless of case. Invoke the function, providing as a parameter an array for the function to alphabetize. Expect the first item in the array to be a string, and that it is equal to whatever string from the provided array ought to be first.Note: Don't forget that if your string contains double-quotes, it should be wrapped in single quotes, or vice-versa.
- Your fourth test should import the
students
array fromstudents.js
. It should be an array, and it should include your name. - Your final test should import the
students
array fromstudents.js
and thepartners
array frompartners.js
. Because of how thepartners
function works, we should expect the length of thepartners
array to be equal to half the length of thestudents
array, rounded down to the nearest even number. Rather than make you figure out how to do that in JavaScript, I've already createdpartners.test.js
and provided a function that can do that for you.
- import the
Extra exercises
Try a little TDD - write a test that expects a lowercased string from a function provided a mixed-case string. Then, write your function in a file in the src folder. Run npm test and watch your test pass! Try this with other tests and functions, too.
Notes
- Remember, to test the result of a function, you must invoke the function. In other words, don't forget to add parentheses (and parameters, if necessary) after the name of the function.
- All the assertions you need for this assignment are documented in the Chai BDD API docs Opens in a new window.