diff --git a/public/docs/ts/latest/guide/_data.json b/public/docs/ts/latest/guide/_data.json index 2b87139b4c..b3d738527e 100644 --- a/public/docs/ts/latest/guide/_data.json +++ b/public/docs/ts/latest/guide/_data.json @@ -184,7 +184,7 @@ "testing": { "title": "Testing", - "intro": "Techniques and practices for testing an Angular app" + "intro": "Techniques and practices for testing an Angular app." }, "typescript-configuration": { diff --git a/public/docs/ts/latest/guide/attribute-directives.jade b/public/docs/ts/latest/guide/attribute-directives.jade index 7c19be8d57..94b27598eb 100644 --- a/public/docs/ts/latest/guide/attribute-directives.jade +++ b/public/docs/ts/latest/guide/attribute-directives.jade @@ -24,7 +24,7 @@ a#directive-overview ## Directives overview There are three kinds of directives in Angular: - + 1. Components — directives with a template. 1. Structural directives — change the DOM layout by adding and removing DOM elements. 1. Attribute directives — change the appearance or behavior of an element, component, or another directive. @@ -32,11 +32,11 @@ a#directive-overview *Components* are the most common of the three directives. You saw a component for the first time in the [QuickStart](../quickstart.html) example. - *Structural Directives* change the structure of the view. + *Structural Directives* change the structure of the view. Two examples are [NgFor](template-syntax.html#ngFor) and [NgIf](template-syntax.html#ngIf). Learn about them in the [Structural Directives](structural-directives.html) guide. - *Attribute directives* are used as attributes of elements. + *Attribute directives* are used as attributes of elements. The built-in [NgStyle](template-syntax.html#ngStyle) directive in the [Template Syntax](template-syntax.html) guide, for example, can change several element styles at the same time. @@ -151,12 +151,12 @@ figure.image-display :marked Angular detects that you're trying to bind to *something* but it can't find this directive - in the module's `declarations` array. - After specifying `HighlightDirective` in the `declarations` array, + in the module's `declarations` array. + After specifying `HighlightDirective` in the `declarations` array, Angular knows it can apply the directive to components declared in this module. :marked - To summarize, Angular found the `myHighlight` attribute on the `
` element. + To summarize, Angular found the `myHighlight` attribute on the `
` element. It created an instance of the `HighlightDirective` class and injected a reference to the `
` element into the directive's constructor which sets the `
` element's background style to yellow. @@ -220,8 +220,8 @@ a#input ### Binding to an _@Input_ property Notice the `@Input` !{_decorator}. It adds metadata to the class that makes the directive's `highlightColor` property available for binding. - - It's called an *input* property because data flows from the binding expression _into_ the directive. + + It's called an *input* property because data flows from the binding expression _into_ the directive. Without that input metadata, Angular rejects the binding; see [below](#why-input "Why add @Input?") for more about that. Try it by adding the following directive binding variations to the `AppComponent` template: @@ -239,7 +239,7 @@ a#input +makeExample('attribute-directives/ts/src/app/app.component.html','color') :marked - The `[myHighlight]` attribute binding both applies the highlighting directive to the `
` element + The `[myHighlight]` attribute binding both applies the highlighting directive to the `
` element
and sets the directive's highlight color with a property binding.
You're re-using the directive's attribute selector (`[myHighlight]`) to do both jobs.
That's a crisp, compact syntax.
@@ -254,8 +254,8 @@ a#input-alias
### Bind to an _@Input_ alias
Fortunately you can name the directive property whatever you want _and_ **_alias it_** for binding purposes.
-
- Restore the original property name and specify the selector as the alias in the argument to `@Input`.
+
+ Restore the original property name and specify the selector as the alias in the argument to `@Input`.
+makeExcerpt('src/app/highlight.directive.ts', 'color', 'src/app/highlight.directive.ts (color property with alias')
:marked
@@ -266,7 +266,7 @@ a#input-alias
+makeExample('attribute-directives/ts/src/app/app.component.html','color')
:marked
- Now that you're binding to `highlightColor`, modify the `onMouseEnter()` method to use it.
+ Now that you're binding to `highlightColor`, modify the `onMouseEnter()` method to use it.
If someone neglects to bind to `highlightColor`, highlight in "red" by default.
+makeExample('attribute-directives/ts/src/app/highlight.directive.3.ts', 'mouse-enter', 'src/app/highlight.directive.ts (mouse enter)')(format='.')
@@ -280,7 +280,7 @@ a#input-alias
It may be difficult to imagine how this directive actually works.
In this section, you'll turn `AppComponent` into a harness that
lets you pick the highlight color with a radio button and bind your color choice to the directive.
-
+
Update `app.component.html` as follows:
+makeExcerpt('attribute-directives/ts/src/app/app.component.html', 'v2', '')
@@ -300,7 +300,7 @@ a#second-property
## Bind to a second property
This highlight directive has a single customizable property. In a real app, it may need more.
- At the moment, the default color — the color that prevails until the user picks a highlight color —
+ At the moment, the default color — the color that prevails until the user picks a highlight color —
is hard-coded as "red". Let the template developer set the default color.
Add a second **input** property to `HighlightDirective` called `defaultColor`:
@@ -313,11 +313,11 @@ a#second-property
How do you bind to a second property when you're already binding to the `myHighlight` attribute name?
As with components, you can add as many directive property bindings as you need by stringing them along in the template.
- The developer should be able to write the following template HTML to both bind to the `AppComponent.color`
+ The developer should be able to write the following template HTML to both bind to the `AppComponent.color`
and fall back to "violet" as the default color.
+makeExample('attribute-directives/ts/src/app/app.component.html', 'defaultColor')(format=".")
:marked
- Angular knows that the `defaultColor` binding belongs to the `HighlightDirective`
+ Angular knows that the `defaultColor` binding belongs to the `HighlightDirective`
because you made it _public_ with the `@Input` !{_decorator}.
Here's how the harness should work when you're done coding.
@@ -368,11 +368,11 @@ a#why-input
+makeExample('attribute-directives/ts/src/app/highlight.directive.ts','color')
:marked
- Either way, the `@Input` !{_decorator} tells Angular that this property is
+ Either way, the `@Input` !{_decorator} tells Angular that this property is
_public_ and available for binding by a parent component.
Without `@Input`, Angular refuses to bind to the property.
- You've bound template HTML to component properties before and never used `@Input`.
+ You've bound template HTML to component properties before and never used `@Input`.
What's different?
The difference is a matter of trust.
@@ -384,9 +384,9 @@ a#why-input
But a component or directive shouldn't blindly trust _other_ components and directives.
The properties of a component or directive are hidden from binding by default.
They are _private_ from an Angular binding perspective.
- When adorned with the `@Input` !{_decorator}, the property becomes _public_ from an Angular binding perspective.
+ When adorned with the `@Input` !{_decorator}, the property becomes _public_ from an Angular binding perspective.
Only then can it be bound by some other component or directive.
-
+
You can tell if `@Input` is needed by the position of the property name in a binding.
* When it appears in the template expression to the ***right*** of the equals (=),
@@ -399,7 +399,7 @@ a#why-input
Now apply that reasoning to the following example:
+makeExample('attribute-directives/ts/src/app/app.component.html','color')(format=".")
:marked
- * The `color` property in the expression on the right belongs to the template's component.
+ * The `color` property in the expression on the right belongs to the template's component.
The template and its component trust each other.
The `color` property doesn't require the `@Input` !{_decorator}.
diff --git a/public/docs/ts/latest/guide/testing.jade b/public/docs/ts/latest/guide/testing.jade
index 2ad8ddeca8..aa1b782da6 100644
--- a/public/docs/ts/latest/guide/testing.jade
+++ b/public/docs/ts/latest/guide/testing.jade
@@ -7,79 +7,94 @@ block includes
- var __objectAsMap = 'object';
:marked
- This guide offers tips and techniques for testing Angular applications.
- Along the way you will learn some general testing principles and techniques but the focus is on
- testing applications written with Angular
+ This guide offers tips and techniques for testing Angular applications.
+ Though this page includes some general testing principles and techniques,
+ the focus is on testing applications written with Angular.
a#top
:marked
- # Table of Contents
- * [Live Examples](#live-examples "Live examples of the tests in this guide")
+ # Contents
+ * [Live examples](#live-examples "Live examples of the tests in this guide")
- * [Introduction to Angular Testing](#testing-intro)
+ * [Introduction to Angular testing](#testing-intro)
- [Tools and technologies](#tools-and-tech)
- [Setup](#setup)
- - [Isolated tests vs. Angular testing utilities](#isolated-v-testing-utilities)
- * [The first test](#1st-karma-test)
- - [run with karma](#run-karma)
- - [debugging karma tests](#test-debugging)
- * [A simple component test](#simple-component-test)
+ - [Isolated unit tests vs. the Angular testing utilities](#isolated-v-testing-utilities)
+ * [The first karma test](#1st-karma-test)
+ - [Run with karma](#run-karma)
+ - [Test debugging](#test-debugging)
+ - [Try the live example](#live-karma-example)
+ * [Test a component](#simple-component-test)
- [_TestBed_](#testbed)
- - [_configureTestingModule_](#configure-testing-module)
- [_createComponent_](#create-component)
- - [_ComponentFixture_, _DebugElement_, _query(By.css)_](#component-fixture)
- - [_detectChanges_](#detect-changes)
- - [_ComponentFixtureAutoDetect _](#auto-detect-changes)
+ - [_ComponentFixture_, _DebugElement_, and _query(By.css)_](#component-fixture)
+ - [The tests](#the-tests)
+ - [_detectChanges_: Angular change detection within a test](#detect-changes)
+ - [Try the live example](#try-example)
+ - [Automatic change detection](#auto-detect-changes)
* [Test a component with an external template](#component-with-external-template)
- - [_async_ setup in _beforeEach_](#async-in-before-each)
- - [_compileComponents_](#compile-components)
+ - [The first asynchronous _beforeEach_](#async-in-before-each)
+ - [_compileComponents_](#compile-components)
+ - [The second synchronous _beforeEach_](#second-before-each)
+ - [Waiting for _compileComponents_](#waiting-compile-components)
+ - [Try the live example](#live-external-template-example)
* [Test a component with a service dependency](#component-with-dependency)
- - [test doubles](#service-test-doubles)
- - [get the injected service](#get-injected-service)
+ - [Provide service test doubles](#service-test-doubles)
+ - [Get injected services](#get-injected-service)
- [_TestBed.get_](#testbed-get)
+ - [Always get the service from an injector](#service-from-injector)
+ - [Final setup and tests](#welcome-spec-setup)
* [Test a component with an async service](#component-with-async-service)
- - [spies](#service-spy)
- - [_async_ test](#async)
+ - [Spying on the real service](#service-spy)
+ - [Synchronous tests](#sync-tests)
+ - [The _async_ funciton in it](#async)
- [_whenStable_](#when-stable)
- - [_fakeAsync_](#fake-async)
- - [_tick_](#tick)
+ - [The _fakeAsync_ function](#fake-async)
+ - [The _tick_ function](#tick)
- [_jasmine.done_](#jasmine-done)
* [Test a component with inputs and outputs](#component-with-input-output)
+ - [Test _DashboardHeroComponent_ stand-alone](#dashboard-standalone)
- [_triggerEventHandler_](#trigger-event-handler)
* [Test a component inside a test host component](#component-inside-test-host)
-
+
* [Test a routed component](#routed-component)
- - [The _inject_ helper](#inject)
+ - [The _inject_ helper function](#inject)
- [Test a routed component with parameters](#routed-component-w-param)
- [Create an _Observable_ test double](#stub-observable)
- [Testing with the _Observable_ test double](#tests-w-observable-double)
* [Use a _page_ object to simplify setup](#page-object)
- * [Setup with module imports](#import-module)
+ * [Set up with module imports](#import-module)
+ * [Import the feature module](#feature-module-import)
* [Override a component's providers](#component-override)
- - [_overrideComponent_](#override-component-method)
- - [Provide a _spy-stub_](#spy-stub)
+ - [The _overrideComponent_ method](#override-component-method)
+ - [Provide a _spy-stub (HeroDetailServiceSpy)_](#spy-stub)
+ - [The override tests](#override-tests)
+ - [More overrides](#more-overrides)
* [Test a _RouterOutlet_ component](#router-outlet-component)
- - [stubbing unneeded components](#stub-component)
+ - [Stubbing unneeded components](#stub-component)
- [Stubbing the _RouterLink_](#router-link-stub)
- [_By.directive_ and injected directives](#by-directive)
- * ["Shallow" component tests with *NO\_ERRORS\_SCHEMA*](#shallow-component-test)
-
+ - [What good are these tests?](#why-stubbed-routerlink-tests)
+ * ["Shallow component tests" with *NO\_ERRORS\_SCHEMA*](#shallow-component-test)
+
* [Test an attribute directive](#attribute-directive)
* [Isolated unit tests](#isolated-unit-tests "Unit testing without the Angular testing utilities")
- [Services](#isolated-service-tests)
+ - [Services with dependencies](#services-with-dependencies)
- [Pipes](#isolated-pipe-tests)
+ - [Write Angular tests too](#write-tests)
- [Components](#isolated-component-tests)
* [Angular testing utility APIs](#atu-apis)
- - [Stand-alone functions](#atu-apis): `async`, `fakeAsync`, etc.
- - [_TestBed_](#testbed-class-summary)
- - [_ComponentFixture_](#component-fixture-api-summary)
+ - [_TestBed_ class summary](#testbed-class-summary)
+ - [The _ComponentFixture_](#component-fixture-api-summary)
+ - [_ComponentFixture_ properties](#component-fixture-properties)
+ - [The _ComponentFixture_ methods](#component-fixture-methods)
- [_DebugElement_](#debug-element-details)
- * [Test environment setup](#setup)
- - [setup files](#setup-files): `karma.conf`, `karma-test-shim`, `systemjs.config`
- - [npm packages](#npm-packages)
- * [FAQ](#faq "Frequently asked questions")
+ * [Test environment setup files](#setup-files)
+ - [npm packages](#npm-packages)
+ * [FAQ: Frequently asked questions](#faq "Frequently asked questions")
:marked
It’s a big agenda. Fortunately, you can learn a little bit at a time and put each lesson to use.
@@ -88,13 +103,13 @@ a#top
This guide presents tests of a sample application that is much like the [_Tour of Heroes_ tutorial](../tutorial).
The sample application and all tests in this guide are available as live examples for inspection, experiment, and download:
- *