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
+42-7Lines changed: 42 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,14 @@ JavaScript Logging Lab
12
12
13
13
Welcome to your first JavaScript lab! You'll notice a few new things in this lesson that we haven't encountered before. Don't worry, we'll walk you through them.
14
14
15
+
### Why test?
16
+
17
+
When we want to run an experiment, we need to develop a hypothesis and we need to test it. So if we want to experiment with whether adding salt to ice water makes it hotter or colder, we need to design an experiment that controls for all of the other variables: we need to _isolate_ our experiment from parts of its environment that aren't relevant to what we hope to test.
18
+
19
+
In programming, tests pick up on the discipline's computer science background. We run tests to verify that our programs behave the way we think they do. Tests help us identify bugs, and they give us a sense of the health of our applications.
20
+
21
+
On Learn, we use tests as teaching tools. Just like in a normal coding environment, we use tests to describe the program's behavior. Unlike in a normal coding environment, you, not we, are in charge of getting the tests to pass — that is, making the app behave like we expect it to.
22
+
15
23
### Structure
16
24
17
25
The structure of this lab — where its files and folders are located — looks roughly like the following:
@@ -33,7 +41,17 @@ All labs will more or less have the same structure. (And READMEs, for that matte
33
41
34
42
### Code-along
35
43
36
-
For now, open up `index.js` in your text editor. You should see, well, nothing. We'll fix that soon.
44
+
For now, open up `index.js` in your text editor. If you're using the Learn IDE, click the "Open" button on this lesson
your IDE should open up. You'll see a sidebar like this:
49
+
50
+

51
+
52
+
If you open up that "javascript-logging-lab..." folder, you'll see a list of files (along with a test/ directory). Click `index.js`, and it will open in the editor.
53
+
54
+
In `index.js`, you should see, well, nothing. We'll fix that soon.
37
55
38
56
Now upon up `test/index-test.js`. Hey, there's something! What's all of this stuff doing?
39
57
@@ -61,7 +79,7 @@ describe('index', () => {
61
79
Then we have a few chunks like
62
80
63
81
```javascript
64
-
it('calls console.error()`, () => {
82
+
it('calls console.error()', () => {
65
83
// this is where the tests are!
66
84
})
67
85
```
@@ -84,13 +102,13 @@ This line reads `index.js` (remember how we said we'd modify that?) and adds its
84
102
85
103
## Running the Tests
86
104
87
-
To run the tests, simply type `learn test`in the Learn IDE. You should see something like
105
+
To run the tests, simply type `learn test` in the terminal part of the Learn IDE. (The terminal is the part below where you've been coding.) You should see something like
For the moment, all of the tests fail. Let's figure out how to get one of them passing! (The rest will be up to you.)
92
110
93
-
Let's take the first one. The test description says, "index calls console.error()". So it sounds like, pretty straight-forwardly, like we should call `console.error()`.
111
+
Let's take the first one. The test description says, "index calls console.error()". So it sounds like, pretty straight-forwardly, like we should _call_`console.error()` somewhere in `index.js`. "Calling" a function means invoking it, causing it to act. We call functions with parentheses: `console.error`_is_ a function, but `console.error()` is a _call_ to the function.
94
112
95
113
In `index.js`, add a call to `console.error()` — you can call it with anything you like (as long as the syntax is valid). We're going to go with
96
114
@@ -100,22 +118,39 @@ console.error("HALP!")
100
118
101
119
Because it seems sufficiently dire.
102
120
103
-
Anyway, let's run the tests again. In the Learn IDE's terminal, run
121
+
Anyway, let's run the tests again. In the Learn IDE's terminal, run
You might often see errors like the ones above: `"Uncaught error: spy was not called"`. Spies are little bits of code that keep track of whether or not they were called. We use them to make sure that a function is called when we expect it to be called.
136
+
137
+
We'll try to rewrite these error messages when possible to be more descriptive about what kinds of calls we expected; but know that sometimes, especially later on, we leave the errors intentionally ambiguous for you to work out.
138
+
115
139
## Your turn
116
140
117
141
Now it's your turn — can you follow a flow similar to the one we followed together above to get the remaining to tests to pass?
118
142
143
+
Imagine that you're building the user interface for a fancy ATM machine.
144
+
Because the developers are hip with the latest trends, they're using
145
+
JavaScript for the user-facing parts.
146
+
147
+
We need a way to send messages to the user: some messages are just updates,
148
+
some are warnings (the user should not continue doing what they just did),
149
+
and some are errors (something broke, and we need to recover).
150
+
151
+
Your job is to identify a way of sending each kind of message. Hint: in
152
+
JavaScript, you'll probably find ways of telling users things with `console`.
153
+
119
154
When all of your tests pass, be sure to run `learn submit` to move on to the next lesson.
0 commit comments