CS2613/journal/_src/posts/2022-09-28-lab-09.md

21 lines
1.6 KiB
Markdown
Raw Normal View History

2022-10-12 09:04:35 -03:00
Title: Lab Nine
Date: 2022-10-12T08:30:00
2022-10-12 11:10:43 -03:00
Tags: cs2613, lab, javascript, tests, jasmine, nyc, test-coverage, debugging, objects, json
2022-10-12 09:04:35 -03:00
2022-10-12 11:10:43 -03:00
In this lab, I learned about how to use tests in javascript and how to view my test coverage
2022-10-12 09:04:35 -03:00
<!-- more -->
2022-10-12 11:10:43 -03:00
## Testing in javascript with Jasmine
With jasmine, tests are stored in *.spec.js files, and each "spec" is a way to give a test a name and designate it a purpose. Specs can be grouped in describe blocks that are often testing one function. Tests follow a syntax of passing in a function result into an `expect` function, which then tests it with the `toBe` function and if the results are the same the test passes.
## Viewing test coverage with nyc
With nyc you can view the test coverage of a jasmine test suite, and it will show you what percent of functions, and lines are uncovered, as well as which lines are not covered with a test.
## Debugging javascript
You can debug a javascript file with the `node inspect "filename.js"` command, and you can then inspect it from the command line or use an interactive debugger in a chrome based browser.
## Objects in javascript
Objects in javascript are similar to mutable hash tables, and you can see this as an object function is just the "key" to a function inside the object.
## Json parsing
In javascript you can parse a json file and parse it directly into an object. You can then perform any actions on this object. Assuming you are aware of what the object should contain you can then perform objects actually fitting of the object (like searching for a name in a json array of people).