Skip to content

Commit 7b3701e

Browse files
committed
Merge branch 'master' into solution
2 parents 5afbe56 + 1a54850 commit 7b3701e

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

README.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ JavaScript Logging Lab
1212

1313
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.
1414

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+
1523
### Structure
1624

1725
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
3341

3442
### Code-along
3543

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
45+
46+
![learn open](https://curriculum-content.s3.amazonaws.com/skills-based-js/learn_open.png)
47+
48+
your IDE should open up. You'll see a sidebar like this:
49+
50+
![learn IDE sidebar](https://curriculum-content.s3.amazonaws.com/skills-based-js/learn_ide_sidebar.png)
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.
3755

3856
Now upon up `test/index-test.js`. Hey, there's something! What's all of this stuff doing?
3957

@@ -61,7 +79,7 @@ describe('index', () => {
6179
Then we have a few chunks like
6280

6381
``` javascript
64-
it('calls console.error()`, () => {
82+
it('calls console.error()', () => {
6583
// this is where the tests are!
6684
})
6785
```
@@ -84,13 +102,13 @@ This line reads `index.js` (remember how we said we'd modify that?) and adds its
84102

85103
## Running the Tests
86104

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
88106

89-
![failures](https://curriculum-content.s3.amazonaws.com/skills-based-js/console_lab_test_failures.png)
107+
![failures](https://curriculum-content.s3.amazonaws.com/skills-based-js/console_logging_lab_all_failing.png)
90108

91109
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.)
92110

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.
94112

95113
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
96114

@@ -100,22 +118,39 @@ console.error("HALP!")
100118

101119
Because it seems sufficiently dire.
102120

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
104122

105123
``` javascript
106124
learn test
107125
```
108126

109127
We should now see:
110128

111-
![one passing](https://curriculum-content.s3.amazonaws.com/skills-based-js/console_lab_test_one_passing.png)
129+
![one passing](https://curriculum-content.s3.amazonaws.com/skills-based-js/console_logging_lab_one_passing.png)
112130

113131
Nice! We got the first one to pass!
114132

133+
## A note about spies
134+
135+
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+
115139
## Your turn
116140

117141
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?
118142

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+
119154
When all of your tests pass, be sure to run `learn submit` to move on to the next lesson.
120155

121156
## Resources

test/index-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('index', () => {
1414
jsdom.env(html, [src], {
1515
virtualConsole: jsdom.createVirtualConsole().sendTo(console)
1616
}, (err, window) => {
17-
expect(spy).toHaveBeenCalled()
17+
expect(spy).toHaveBeenCalled('expected console.error to have been called')
1818
console.error.restore()
1919
done()
2020
})
@@ -26,7 +26,7 @@ describe('index', () => {
2626
jsdom.env(html, [src], {
2727
virtualConsole: jsdom.createVirtualConsole().sendTo(console)
2828
}, (err, window) => {
29-
expect(spy).toHaveBeenCalled()
29+
expect(spy).toHaveBeenCalled('expected console.log to have been called')
3030
console.log.restore()
3131
done()
3232
})
@@ -38,7 +38,7 @@ describe('index', () => {
3838
jsdom.env(html, [src], {
3939
virtualConsole: jsdom.createVirtualConsole().sendTo(console)
4040
}, (err, window) => {
41-
expect(spy).toHaveBeenCalled()
41+
expect(spy).toHaveBeenCalled('expected console.warn to have been called')
4242
console.warn.restore()
4343
done()
4444
})

0 commit comments

Comments
 (0)