-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preliminary Concepts #1047
Comments
Install MochaBefore writing any test you'll need to use Node.js and npm to set up a JavaScript project and install Mocha.
A JavaScript project is a directory of files. The following command creates a file package.json that can be used to manage packages for the project.
After running this command you will be prompted to enter information about your project. It's okay to skip some fields if you're not ready to enter that information. With your project setup, you can install packages.
Here's what this command means:
Once you npm install packages, you can find the packages and all their dependencies in the node_modules folder. The new directory structure contains the following: project The ... in the file structure represents other packages that are a dependency for Mocha.
Install Mocha:
You can view package.json in the text editor. You can now see mocha as a dependency. |
After installing Mocha as a dependency we can run it in two ways.
The second (and recommended) method is to add a script to package.json. In the scripts object in package.json, set the value of "test": "mocha". It should look like this:
Now you can call Mocha with the following command:
Instead of manually running each test in the test directory, you can use this command to run the full test suite automatically. |
Testing is an essential part of development. When used properly, testing can catch and identify issues with your implementation code before you deploy it to users. Instead of testing every function manually, developers automate their tests with a test framework.
Developers use test frameworks to organize and automate tests that provide useful feedback when errors occur. We will use the Mocha test framework to write tests against JavaScript methods.
We'll learn:
The text was updated successfully, but these errors were encountered: