parent
aec0892cf7
commit
2304cdd753
|
@ -112,7 +112,7 @@ a#top
|
||||||
|
|
||||||
* [Provide service test doubles](#service-test-doubles)
|
* [Provide service test doubles](#service-test-doubles)
|
||||||
|
|
||||||
[测试复制品](#service-test-doubles)
|
[测试替身](#service-test-doubles)
|
||||||
|
|
||||||
* [Get injected services](#get-injected-service)
|
* [Get injected services](#get-injected-service)
|
||||||
|
|
||||||
|
@ -1280,14 +1280,14 @@ a#service-test-doubles
|
||||||
:marked
|
:marked
|
||||||
### Provide service test doubles
|
### Provide service test doubles
|
||||||
|
|
||||||
### 提供服务复制品
|
### 提供服务替身
|
||||||
|
|
||||||
A _component-under-test_ doesn't have to be injected with real services.
|
A _component-under-test_ doesn't have to be injected with real services.
|
||||||
In fact, it is usually better if they are test doubles (stubs, fakes, spies, or mocks).
|
In fact, it is usually better if they are test doubles (stubs, fakes, spies, or mocks).
|
||||||
The purpose of the spec is to test the component, not the service,
|
The purpose of the spec is to test the component, not the service,
|
||||||
and real services can be trouble.
|
and real services can be trouble.
|
||||||
|
|
||||||
被测试的组件不一定要注入真正的服务。实际上,服务的复制品(stubs, fakes, spies或者mocks)通常会更加合适。
|
被测试的组件不一定要注入真正的服务。实际上,服务的替身(stubs, fakes, spies或者mocks)通常会更加合适。
|
||||||
spec的主要目的是测试组件,而不是服务。真实的服务可能自身有问题。
|
spec的主要目的是测试组件,而不是服务。真实的服务可能自身有问题。
|
||||||
|
|
||||||
Injecting the real `UserService` could be a nightmare.
|
Injecting the real `UserService` could be a nightmare.
|
||||||
|
@ -1297,7 +1297,7 @@ a#service-test-doubles
|
||||||
It is far easier and safer to create and register a test double in place of the real `UserService`.
|
It is far easier and safer to create and register a test double in place of the real `UserService`.
|
||||||
|
|
||||||
注入真实的`UserService`有可能很麻烦。真实的服务可能询问用户登录凭据,也可能试图连接认证服务器。
|
注入真实的`UserService`有可能很麻烦。真实的服务可能询问用户登录凭据,也可能试图连接认证服务器。
|
||||||
可能很难处理这些行为。所以在真实的`UserService`的位置创建和注册`UserService`复制品,会让测试更加容易和安全。
|
可能很难处理这些行为。所以在真实的`UserService`的位置创建和注册`UserService`替身,会让测试更加容易和安全。
|
||||||
|
|
||||||
This particular test suite supplies a minimal `UserService` stub that satisfies the needs of the `WelcomeComponent`
|
This particular test suite supplies a minimal `UserService` stub that satisfies the needs of the `WelcomeComponent`
|
||||||
and its tests:
|
and its tests:
|
||||||
|
@ -1494,6 +1494,9 @@ a#service-spy
|
||||||
Spying on the real service isn't always easy, especially when the real service has injected dependencies.
|
Spying on the real service isn't always easy, especially when the real service has injected dependencies.
|
||||||
You can _stub and spy_ at the same time, as shown in [an example below](#spy-stub).
|
You can _stub and spy_ at the same time, as shown in [an example below](#spy-stub).
|
||||||
|
|
||||||
|
刺探真实的服务往往并不容易,特别是真实的服务依赖其它服务时。
|
||||||
|
我们可以同时*打桩和刺探*,就像[后面的例子](#spy-stub)那样。
|
||||||
|
|
||||||
:marked
|
:marked
|
||||||
Here are the tests with commentary to follow:
|
Here are the tests with commentary to follow:
|
||||||
|
|
||||||
|
@ -2141,7 +2144,8 @@ a#inject
|
||||||
:marked
|
:marked
|
||||||
Do not configure the `TestBed` after calling `inject`.
|
Do not configure the `TestBed` after calling `inject`.
|
||||||
|
|
||||||
不要再调用`inject`以后再试图配置`TestBed`。
|
不要在调用`inject`以后再试图配置`TestBed`。
|
||||||
|
|
||||||
a(href="#top").to-top Back to top
|
a(href="#top").to-top Back to top
|
||||||
a(href="#top").to-top 回到顶部
|
a(href="#top").to-top 回到顶部
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,6 @@
|
||||||
margin-top: -($unit * 0);
|
margin-top: -($unit * 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
p.original-english {
|
|
||||||
margin-top: -($unit * 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
.card {
|
.card {
|
||||||
height: auto;
|
height: auto;
|
||||||
min-height: 194px;
|
min-height: 194px;
|
||||||
|
@ -121,3 +117,9 @@ body, .main-nav .main-nav-button, .translated-cn {
|
||||||
img {
|
img {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.l-sub-section, .alert {
|
||||||
|
p {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue