Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 93a646d

Browse files
committed
(docs) testing and toh formatting improvements
1 parent cdec7d1 commit 93a646d

File tree

12 files changed

+160
-118
lines changed

12 files changed

+160
-118
lines changed

public/docs/_examples/quickstart/js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// #docregion class-w-annotations
55
var AppComponent = ng
6-
ng.Component({
6+
.Component({
77
selector: 'my-app',
88
template: '<h1>My First Angular 2 App</h1>'
99
})

public/docs/_examples/quickstart/js/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<!-- #docregion -->
33
<html>
44
<head>
5+
<title>Angular 2 QuickStart</title>
56
<script src="node_modules/angular2/bundles/angular2.sfx.dev.js"></script>
67
<script src="app.js"></script>
78
</head>

public/docs/_examples/quickstart/ts/src/index.1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html>
44

55
<head>
6-
<title>Getting Started</title>
6+
<title>Angular 2 QuickStart</title>
77
<script src="https://code.angularjs.org/tools/system.js"></script>
88
<script src="https://code.angularjs.org/tools/typescript.js"></script>
99
<script src="https://code.angularjs.org/2.0.0-alpha.42/angular2.dev.js"></script>

public/docs/_examples/quickstart/ts/src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html>
44

55
<head>
6-
<title>Getting Started</title>
6+
<title>Angular 2 QuickStart</title>
77
<!-- #docregion libraries -->
88
<script src="../node_modules/systemjs/dist/system.src.js"></script>
99
<script src="../node_modules/angular2/bundles/angular2.dev.js"></script>

public/docs/ts/latest/testing/_data.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,27 @@
22
"_listtype": "ordered",
33

44
"index": {
5-
"title": "Testing Guides"
5+
"title": "Testing Guides",
6+
"intro": "Techniques and practices for testing an Angular 2 app"
67
},
78

89
"jasmine-testing-101": {
9-
"title": "Jasmine Testing 101"
10+
"title": "Jasmine Testing 101",
11+
"intro": "The basics of testing anything with Jasmine"
1012
},
1113

1214
"application-under-test": {
13-
"title": "The Application Under Test"
15+
"title": "The Application Under Test",
16+
"intro": "A quick look at the application we will test"
1417
},
1518

1619
"first-app-tests": {
17-
"title": "First App Tests"
20+
"title": "First App Tests",
21+
"intro": "The first test of a simple, non-Angular part of our app"
1822
},
1923

2024
"testing-an-angular-pipe": {
21-
"title": "Testing an Angular Pipe"
25+
"title": "Testing an Angular Pipe",
26+
"intro": "We test an Angular-aware part of our app"
2227
}
2328
}

public/docs/ts/latest/testing/application-under-test.jade

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,7 @@ figure.image-display
3232

3333
We’ll examine the implementation details as we evolve our tests.
3434

35+
.l-main-section
36+
:markdown
3537
## What’s Next?
3638
Now that we’re familiar with how the test app works, we’re ready to poke at it with our first application tests written in Jasmine.

public/docs/ts/latest/testing/first-app-tests.jade

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ include ../../../../_includes/_util-fns
1616
we introduced in the [QuickStart](../quickstart.html) and
1717
the [Tour of Heroes](../tutorial/) tutorial
1818
such as <code>npm</code>, <code>gulp</code>, and <code>live-server</code>.
19+
20+
.l-main-section
1921
:markdown
2022
## Create the test-runner HTML
2123

@@ -44,6 +46,8 @@ include ../../../../_includes/_util-fns
4446

4547
We’re picking up right where we left off. All we’ve done is change the title.
4648

49+
.l-main-section
50+
:markdown
4751
## Update `package.json` for testing
4852

4953
We’ll assume that the application has `package.json` file that looks more or less like
@@ -66,6 +70,8 @@ pre.prettyprint.lang-bash
6670

6771
That command will launch `live-server` and open a browser to the `unit-tests.html` page we just wrote.
6872

73+
.l-main-section
74+
:markdown
6975
## First app tests
7076

7177
Believe it or not … we could start testing *some* of our app right away. For example, we can test the `Hero` class:
@@ -128,6 +134,8 @@ pre.prettyprint.lang-bash
128134

129135
The description should be sufficient to identify the tested application part and its source file. Almost any convention will do as long as you and your team follow it consistently and are never confused.
130136

137+
.l-main-section
138+
:markdown
131139
## Run the tests
132140

133141
Open one terminal window and run the watching compiler command: `npm run tsc`
@@ -139,6 +147,8 @@ pre.prettyprint.lang-bash
139147
figure.image-display
140148
img(src='/resources/images/devguide/first-app-tests/passed-2-specs-0-failures.png' style="width:400px;" alt="Two passing tests")
141149

150+
151+
.l-main-section
142152
:markdown
143153
## Critique
144154

@@ -150,6 +160,8 @@ figure.image-display
150160

151161
We need to relocate these tests to a separate file. Let’s do that next.
152162

163+
.l-main-section
164+
:markdown
153165
## Where do tests go?
154166

155167
Some people like to keep their tests in a `tests` folder parallel to the application source folder.
@@ -165,6 +177,8 @@ figure.image-display
165177

166178
You may put your tests elsewhere if you wish. We’re putting ours inside the app, next to the source files that they test.
167179

180+
.l-main-section
181+
:markdown
168182
## First spec file
169183

170184
**Create** a new file, ** `hero.spec.ts` ** in `src/app` next to `hero.ts`.
@@ -209,7 +223,7 @@ figure.image-display
209223
<script src="app/hero.js"></script>
210224
<script src="app/hero.spec.js"></script>
211225

212-
## Run and Fail
226+
### Run and Fail
213227

214228
Look over at the browser (live-server will have reloaded it). The browser displays
215229

@@ -220,10 +234,12 @@ figure.image-display
220234
That’s Jasmine saying “**things are _so_ bad that _I’m not running any tests_.**”
221235

222236
Open the browser’s Developer Tools (F12, Ctrl-Shift-i). There’s an error:
223-
```
237+
238+
code-example(format="" language="html").
224239
Uncaught ReferenceError: exports is not defined
225-
```
226240

241+
.l-main-section
242+
:markdown
227243
## Load tests with systemjs
228244

229245
The immediate cause of the error is the `export` statement in `hero.ts`.
@@ -278,6 +294,8 @@ figure.image-display
278294
figure.image-display
279295
img(src='/resources/images/devguide/first-app-tests/test-passed-once-again.png' style="width:400px;" alt="Tests passed once again")
280296

297+
298+
.l-main-section
281299
:markdown
282300
## Observations
283301

@@ -307,6 +325,8 @@ figure.image-display
307325
So we must wait until the import completes and only then call the window `onLoad` handler.
308326
Jasmine re-starts, this time with our imported test queued up.
309327

328+
.l-main-section
329+
:markdown
310330
## What’s Next?
311331
We are able to test a part of our application with simple Jasmine tests.
312332
The part was a stand-alone class that made no mention or use of Angular.

public/docs/ts/latest/testing/jasmine-testing-101.jade

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pre.prettyprint.lang-bash
3636
:markdown
3737
The browser is nice during development of a few tests. It’s not the best venue for working with a lot of tests and it won’t do at all for build automation. We’ll switch to the karma test-runner when the time comes. But the browser will do for now.
3838

39-
.l-main-section
4039
:markdown
4140
Create a new file called`unit-tests.html` and enter the following:
4241
```
@@ -73,7 +72,9 @@ figure.image-display
7372

7473
:markdown
7574
It doesn’t get much simpler than that!
76-
75+
76+
.l-main-section
77+
:markdown
7778
## First TypeScript Test
7879
Perhaps too simple. We won’t write our entire test suite inside one HTML file.
7980
Let’s **extract** that line of test code to a **new file in `src` called `1st.spec.ts` ** .
@@ -82,7 +83,6 @@ figure.image-display
8283
:markdown
8384
Among Jasmine developers, a test is known as a “spec” and test filenames include the word “spec”. We’ll stick with that convention.
8485

85-
.l-main-section
8686
:markdown
8787
The test we wrote is valid TypeScript because any JavaScript is valid TypeScript. But let’s make it more modern with an arrow function:
8888
```
@@ -96,6 +96,8 @@ figure.image-display
9696

9797
That’s a reminder that we need to compile our TypeScript test files as we do our TypeScript application files. Do that next.
9898

99+
.l-main-section
100+
:markdown
99101
## Prepare for TypeScript
100102

101103
As we’ve seen before, we first have to tell the compiler how to compile our TypeScript files with
@@ -143,6 +145,8 @@ pre.prettyprint.lang-bash
143145

144146
We should get the same Jasmine test-runner output as before.
145147

148+
.l-main-section
149+
:markdown
146150
## Add a describe and another test
147151

148152
We can’t tell what file produced these test results. We only have one file at the moment but soon we’ll write more.
@@ -189,6 +193,8 @@ figure.image-display
189193
:markdown
190194
We can re-run just the failing test by double-clicking it. Try it!
191195

196+
.l-main-section
197+
:markdown
192198
## Debug the test
193199
Suppose we didn’t know what was going on. We can debug it in the browser.
194200

@@ -214,10 +220,14 @@ figure.image-display
214220

215221
Congratulations … you’ve completed Jasmine testing 101.
216222

223+
.l-main-section
224+
:markdown
217225
## Learn more
218226
Learn more about basic Jasmine testing here
219227
[Resources TBD](./#)
220-
228+
229+
.l-main-section
230+
:markdown
221231
## What’s Next?
222232
Now that we’re familiar with Jasmine on its own, we’re ready to test an application.
223233

public/docs/ts/latest/testing/testing-an-angular-pipe.jade

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ include ../../../../_includes/_util-fns
99

1010
We use it our `hero-detail.component.html` template to turn a hero name like “eeny weenie” into “Eeny Weenie”
1111

12-
The code for `InitCapsPipe` in `init-caps-pipe.ts` is quite brief:
13-
14-
code-example(format="linenums").
15-
&lt;h2&gt;{{hero.name | initCaps}} is {{userName}}'s current super hero!&lt;/h2&gt;
12+
code-example(format="linenums" language="html" escape="html").
13+
<h2>{{hero.name | initCaps}} is {{userName}}'s current super hero!</h2>
1614

1715
:markdown
1816
The code for `InitCapsPipe` in `init-caps-pipe.ts` is quite brief:
@@ -61,9 +59,10 @@ figure.image-display
6159
in the console window, we would see that SystemJS
6260
tried to load Angular and couldn't find it.
6361

64-
```
62+
code-example(format="" language="html" escape="html").
6563
GET http://127.0.0.1:8080/src/angular2/angular2 404 (Not Found)
66-
```
64+
65+
:markdown
6766
We are writing an Angular application afterall and
6867
we were going to need Angular sooner or later. That time has come.
6968
The `InitCapsPiep` clearly depends on Angular as is clear in the first few lines:

public/docs/ts/latest/tutorial/index.jade

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ include ../../../../_includes/_util-fns
2424
Angular can do whatever we need it to do.
2525
We'll be covering a lot of ground at an introductory level but we’ll find plenty of links
2626
to chapters with greater depth.
27-
27+
28+
.l-main-section
29+
:markdown
2830
## The End Game
2931

3032
Here's a visual idea of where we're going in this tour, beginning with the "Dashboard"
@@ -59,7 +61,9 @@ include ../../../../_includes/_util-fns
5961

6062
We can click a hero and have the router race us over to a "Hero Details" view
6163
again.
62-
64+
65+
.l-main-section
66+
:markdown
6367
## How We Roll
6468

6569
We’ll build this Tour of Heroes together, step by step.

0 commit comments

Comments
 (0)