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
expectassertion 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
studentCheckfunction fromdoesStudentDuplicateExist.test.js. Test the result of thestudentCheckfunction to ensure that it is true that there are no duplicates in the students array. - Your next test should import the
stripHTMLfunction 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
arocfunction 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
studentsarray fromstudents.js. It should be an array, and it should include your name. - Your final test should import the
studentsarray fromstudents.jsand thepartnersarray frompartners.js. Because of how thepartnersfunction works, we should expect the length of thepartnersarray to be equal to half the length of thestudentsarray, rounded down to the nearest even number. Rather than make you figure out how to do that in JavaScript, I've already createdpartners.test.jsand 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.