translate: 3450

This commit is contained in:
Rex 2016-10-05 21:44:04 +01:00
parent 08ef04a968
commit 020722e3ea
1 changed files with 63 additions and 3 deletions

View File

@ -3269,7 +3269,7 @@ code-example(format="." language="javascript").
Each overide method takes a `MetadataOverride<T>` where `T` is the kind of metadata
appropriate to the method, the parameter of an `@NgModule`, `@Component`, `@Directive`, or `@Pipe`.
每一个重载方法接受一个`MetadataOverride<T>`,这里`T`是适合这个方法的元数据类型,也就是`@NgModule`、`@Component`、`@Directive`或者`@Pipe`的参数。
code-example(format="." language="javascript").
type MetadataOverride<T> = {
@ -3282,16 +3282,32 @@ code-example(format="." language="javascript").
#testbed-methods
:marked
The `TestBed` API consists of static class methods that either update or reference a _global_ instance of the`TestBed`.
`TestBed`的API包含了一系列静态类方法它们更新或者引用**全局**的`TestBed`实例。
Internally, all static methods cover methods of the current runtime `TestBed` instance that is also returned by the `getTestBed()` function.
在内部,所有静态方法在`getTestBed()`函数返回的当前运行时间的`TestBed`实例上都有对应的方法。
Call `TestBed` methods _within_ a `BeforeEach()` to ensure a fresh start before each individual test.
在`BeforeEach()`内调用`TestBed`方法,这样确保在运行每个单独测试时,都有崭新的开始。
Here are the most important static methods, in order of likely utility.
这里列出了最重要的静态方法,以使用频率排序:
table
tr
th Methods
th Description
th
:marked
Methods
方法
th
:marked
Description
描述
tr
td(style="vertical-align: top") <code>configureTestingModule</code>
td
@ -3300,9 +3316,14 @@ table
establish the [initial test environment](##testbed-initTestEnvironment) and a default testing module.
The default testing module is configured with basic declaratives and some Angular service substitutes (e.g. `DebugDomRender`)
that every tester needs.
测试垫片(`karma-test-shim`, `browser-test-shim`)创建了[初始测试环境](##testbed-initTestEnvironment)和默认测试模块。
默认测试模块是使用基本声明和一些Angular服务替代品比如`DebugDomRender`),它们是所有测试都需要的。
Call `configureTestingModule` to refine the testing module configuration for a particular set of tests
by adding and removing imports, declarations (of components, directives, and pipes), and providers.
调用`configureTestingModule`来为一套特定的测试定义测试模块配置,添加和删除导入、(组件、指令和管道的)声明和服务提供商。
tr
td(style="vertical-align: top") <code>compileComponents</code>
td
@ -3312,14 +3333,23 @@ table
or `styleUrls` because fetching component template and style files is necessarily asynchronous.
See [above](#compile-components).
在你完成配置以后异步编译测试模块。
如果**任何**测试组件有`templateUrl`或`styleUrls`,那么你**必须**调用这个方法。因为获取组件模块和样式文件必须是异步的。
参见[上面的描述](#compile-components)。
Once called, the `TestBed` configuration is frozen for the duration of the current spec.
一旦调用,`TestBed`的配置就会在当前测试期间被冻结。
tr
td(style="vertical-align: top") <code>createComponent<T></code>
td
:marked
Create an instance of a component of type `T` based on the current `TestBed` configuration.
Once called, the `TestBed` configuration is frozen for the duration of the current spec.
基于当前`TestBed`的配置创建一个类型为T的组件实例。
一旦调用,`TestBed`的配置就会在当前测试期间被冻结。
tr
td(style="vertical-align: top") <code>overrideModule</code>
td
@ -3327,24 +3357,33 @@ table
Replace metadata for the given `NgModule`. Recall that modules can import other modules.
The `overrideModule` method can reach deeply into the current testing module to
modify one of these inner modules.
替换指定的`NgModule`的元数据。回想一下,模块可以导入其他模块。
`overrideModule`方法可以深入到当前测试模块深处,修改其中一个内部模块。
tr
td(style="vertical-align: top") <code>overrideComponent</code>
td
:marked
Replace metadata for the given component class which could be nested deeply
within an inner module.
替换指定组件类的元数据,该组件类可能嵌套在一个很深的内部模块中。
tr
td(style="vertical-align: top") <code>overrideDirective</code>
td
:marked
Replace metadata for the given directive class which could be nested deeply
within an inner module.
替换指定的指令类的元数据,该指令可能嵌套在一个很深的内部模块中。
tr
td(style="vertical-align: top") <code>overridePipe</code>
td
:marked
Replace metadata for the given pipe class which could be nested deeply
within an inner module.
替换指定的管道类的元数据,该管道可能嵌套在一个很深的内部模块中。
tr
td(style="vertical-align: top").
<a id="testbed-get"></a>
@ -3353,17 +3392,27 @@ table
:marked
Retrieve a service from the current `TestBed` injector.
从当前`TestBed`注入器获取一个服务。
The `inject` function is often adequate for this purpose.
But `inject` throws an error if it can't provide the service.
What if the service is optional?
`inject`函数通常很适合这个任务。
但是如果`inject`不能提供服务,它会抛出错误。
如果服务是可选的呢?
The `TestBed.get` method takes an optional second parameter,
the object to return if Angular can't find the provider
(`null` in this example):
`TestBed.get`方法接受一个可选的第二参数它是在Angular找不到所需提供商时返回的对象。在本例中为`null`
+makeExample('testing/ts/app/bag/bag.spec.ts', 'testbed-get')(format=".")
:marked
Once called, the `TestBed` configuration is frozen for the duration of the current spec.
一旦调用,`TestBed`的配置就会在当前测试期间被冻结。
tr
td(style="vertical-align: top").
<a id="testbed-initTestEnvironment"></a>
@ -3372,21 +3421,32 @@ table
:marked
Initialize the testing environment for the entire test run.
为整套测试的运行初始化测试环境。
The testing shims (`karma-test-shim`, `browser-test-shim`) call it for you
so there is rarely a reason for you to call it yourself.
测试垫片(`karma-test-shim`, `browser-test-shim`)会为你调用它,所以你很少需要自己调用它。
This method may be called _exactly once_. Call `resetTestEnvironment` first
if you absolutely need to change this default in the middle of your test run.
这个方法只能被调用**一次**。如果确实需要在测试运行期间变换这个默认设置,那么先调用`resetTestEnvironment`。
Specify the Angular compiler factory, a `PlatformRef`, and a default Angular testing module.
Alternatives for non-browser platforms are available in the general form
`@angular/platform-<platform_name>/testing/<platform_name>`.
指定Angular编译器工厂`PlatformRef`和默认Angular测试模块。
非浏览器平台的替代以`@angular/platform-<platform_name>/testing/<platform_name>`的形式提供。
tr
td(style="vertical-align: top") <code>resetTestEnvironment</code>
td
:marked
Reset the initial test environment including the default testing module.
重设初始测试环境,包括默认测试模块在内。
:marked
A few of the `TestBed` instance methods are not covered by static `TestBed` _class_ methods.
These are rarely needed.