You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+4-33Lines changed: 4 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -6,44 +6,15 @@ There will eventually be a suggested order of completion, but at this time since
6
6
2. Repeat String
7
7
3. Reverse String
8
8
9
-
## Setting Up
9
+
## How To Use These Exercises
10
10
Before you start you should have a few things installed on your machine:
11
11
1. NPM. To check if you have NPM installed, type `npm --version` in your terminal. If you get back `Command 'npm' not found, but can be installed with:`, do NOT follow the instructions in the terminal to install with `apt-get`. (This causes permission issues.) Instead, install Node with NVM by following the instructions [here](https://github.com/TheOdinProject/curriculum/blob/master/foundations/installations/installing_node.md).
12
-
2. A copy of this repository. Copies of repositories on your machine are called clones. If you need help cloning, you can learn how [here](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository).
13
-
3. Jest. Jest is a testing framework for JavaScript. To install it, navigate to your local copy of the repository and type `npm install --save-dev jest`. We use `--save-dev` here to specify this module is for development purposes only.
14
-
15
-
Once Jest has been installed, you should see a few additional files and folders appear in your repository:
16
-
17
-
*:file_folder: node_modules
18
-
*:page_facing_up: package-lock.json
19
-
*:page_facing_up: package.json
20
-
21
-
Open the `package.json` file in your text editor, and add the following code:
12
+
2. Jest. Jest is a testing framework for JavaScript. To install it, type `npm install --save-dev jest`. We use `--save-dev` here to specify this module is for development purposes only.
13
+
3. A copy of this repository. Copies of repositories on your machine are called clones. If you need help cloning, you can learn how [here](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository).
22
14
23
-
```json
24
-
"scripts": {
25
-
"test": "jest"
26
-
}
27
-
```
28
-
29
-
So that the end result looks something like this (don't worry if your jest version is different):
30
-
31
-
```json
32
-
{
33
-
"devDependencies": {
34
-
"jest": "^26.6.3"
35
-
}, <-- take note of the comma here
36
-
"scripts": {
37
-
"test": "jest"
38
-
}
39
-
}
40
-
```
41
-
That's it! Jest should be fully functional now. Onto the next section where we learn how to use it.
42
-
43
-
## How To Use These Exercises
44
15
Each exercise includes 3 files: a markdown file with a description of the task, an empty (or mostly empty) JavaScript file, and a set of tests. To complete an exercise, you'll need to go to the exercise directory with `cd exerciseName` in the terminal and run `npm test exerciseName.spec.js`. This should run the test file and show you the output. When you first run a test, it will fail. This is by design! You must open the exercise file and write the code needed to get the test to pass. Some of the exercises have test conditions defined in their spec file that are defined as 'test.skip' compared to 'test'. This is purposeful. After you pass your first 'test', you will change the next 'test.skip' to an 'test' and test your code again. You'll do this until all conditions are satisfied.
45
16
46
-
**Note**: Due to the way Jest handles failed tests, it will return an exit code of 1 if any tests fail. NPM will interpret this as an error and you may see some `npm ERR!` messages after Jest runs. You can ignore these, or run your test with `npm test exerciseName.spec.js --silent` to supress the errors.
17
+
**Note**: Due to the way Jest handles failed tests, it will return an etest.skip code of 1 if any tests fail. NPM will interpret this as an error and you may see some `npm ERR!` messages after Jest runs. You can ignore these, or run your test with `npm test exerciseName.spec.js --silent` to supress the errors.
47
18
48
19
The first exercise, `helloWorld`, will walk you through the process in-depth.
Copy file name to clipboardExpand all lines: helloWorld/README.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -13,14 +13,14 @@ Let's look at the spec file first:
13
13
consthelloWorld=require('./helloWorld');
14
14
15
15
describe('Hello World', function() {
16
-
it('says hello world', function() {
16
+
test('says hello world', function() {
17
17
expect(helloWorld()).toEqual('Hello, World!');
18
18
});
19
19
});
20
20
```
21
21
At the very top of the file we use `require()` to import the code from the javascript file (`helloWorld.js`) so that we can test it.
22
22
23
-
The next block (`describe()`) is the body of the test. Basically, all it's doing is running your code and testing to see if the output is correct. The `it()` function describes what should be happening in plain english and then includes the `expect()` function. For this simple example it should be pretty simple to read.
23
+
The next block (`describe()`) is the body of the test. Basically, all it's doing is running your code and testing to see if the output is correct. The `test()` function describes what should be happening in plain english and then includes the `expect()` function. For this simple example it should be pretty simple to read.
24
24
25
25
For now you do not need to worry about how to write tests, but you should try to get comfortable enough with the syntax to figure out what the tests are asking you to do. Go ahead and run the tests by entering `jasmine helloWorld.spec.js` in the terminal and watch it fail. The output from that command should tell you exactly what went wrong with your code. In this case, running the `helloWorld()` function should return the phrase 'Hello, World!' but instead it returns an empty string...
0 commit comments