我想为我的test/src/rating/rating.html/dart
组件(<rating>
)编写单元测试(lib/rating/rating.dart/html
)。
void main() {
useHtmlEnhancedConfiguration();
ng.Scope _rootScope;
dom.Element _element;
ngMock.TestBed _tb;
setUp(() {
try {
ngMock.setUpInjector();
ngMock.module((ng.Module module) {
module.install(new RatingModule());
});
ngMock.inject((ng.Scope scope, ngMock.TestBed testBed) {
_rootScope = scope;
_rootScope['rate'] = 3;
_tb = testBed;
_element = _tb.compile('<rating value="rate"></rating>', scope: _rootScope);
_rootScope.$digest();
});
print('setUp done');
} catch(e) {
print(e);
}
});
第_element = _tb.compile('<rating value="rate>...
行失败
[意外请求:GET packages / bootstrap_angular / rating / rating.html
我将组件templateUrl更改为模板,并将模板HTML指定为字符串并删除了异常。
我做错了还是不支持?
答案 0 :(得分:2)
我创建了issue in the Angular.dart GitHub repository。 随着我得到的回应,我认为这有效,但是相当冗长:
void main() {
useHtmlEnhancedConfiguration();
ng.Scope _rootScope;
dom.Element _element;
ngMock.TestBed _tb;
ngMock.MockHttpBackend _backend; // new
setUp(() {
Future f;
try {
ngMock.setUpInjector();
ngMock.module((ng.Module module) {
module.install(new RatingModule());
});
ngMock.inject((ng.Scope scope, ngMock.TestBed testBed) {
_rootScope = scope;
_rootScope['rate'] = 3;
_tb = testBed;
f = dom.HttpRequest.getString('/bootstrap_angular/packages/bootstrap_angular/rating/rating.html') // new
.then((ratingTemplate) { // new
_backend = new ngMock.MockHttpBackend(); // new
print(ratingTemplate); // just debug output
_backend.expect('GET').respond(ratingTemplate); // new
_element = _tb.compile('<rating value="rate"></rating>', scope: _rootScope);
var element =_element.shadowRoot.querySelector('i');
_rootScope.$digest();
});
});
} catch(e) {
print(e);
}
return f; // new
// return a future to make the tests wait until setUp is done
// found in this question
// How to wait for an asynchronous setup in a unit test, in Dart?
// http://stackoverflow.com/questions/14994518
});