Ken*_*nne 76 unit-testing jasmine angularjs angularjs-service
在下面的示例测试中,原始提供者名称是APIEndpointProvider,但是对于注入和服务实例化,约定似乎必须注入包含它的下划线.这是为什么?
'use strict';
describe('Provider: APIEndpointProvider', function () {
beforeEach(module('myApp.providers'));
var APIEndpointProvider;
beforeEach(inject(function(_APIEndpointProvider_) {
APIEndpointProvider = _APIEndpointProvider_;
}));
it('should do something', function () {
expect(!!APIEndpointProvider).toBe(true);
});
});
Run Code Online (Sandbox Code Playgroud)
我错过了一个更好的解释是什么?
Jos*_*ler 108
下划线是我们可以用来以不同名称注入服务的便利技巧,以便我们可以在本地分配与服务同名的本地变量.
也就是说,如果我们不能这样做,我们必须在本地为服务使用其他名称:
beforeEach(inject(function(APIEndpointProvider) {
AEP = APIEndpointProvider; // <-- we can't use the same name!
}));
it('should do something', function () {
expect(!!AEP).toBe(true); // <-- this is more confusing
});
Run Code Online (Sandbox Code Playgroud)
在$injector试验中使用的是能够只是删除下划线给我们我们想要的模块.除了让我们重复使用相同的名称之外,它什么都不做.
| 归档时间: |
|
| 查看次数: |
10168 次 |
| 最近记录: |