使用新的test库来测试Dart Polymer元素,构建my_element_test.html
as prescribed。请参阅我的回购:polymer-dart-testing。
my_element_test.html
和my_element_test.dart
(注释掉聚合物启动)按预期通过测试:
<!doctype html>
<html>
<head>
<title>My Element Test</title>
<link rel="import" href="packages/polymer_dart_testing/my_element.html">
<link rel="x-dart-test" href="my_element_test.dart">
<script src="packages/test/dart.js"></script>
</head>
<body>
<div>Custom HTML Test is Custom.</div>
<my-element></my-element>
</body>
</html>
import 'package:test/test.dart';
import 'package:polymer_dart_testing/my_element.dart';
import 'package:polymer/polymer.dart';
import 'dart:html';
main() {
setUp(() async {
// await initPolymer();
// return await Polymer.onReady;
});
test('custom_html_test', (){
expect(true, isTrue);
});
}
pub run test...
中的聚合物入口点添加test/my_element_test.html
后,在控制台中加载没有pubspec.yaml
的Dartium并显示自定义元素。transformers:
- polymer:
entry_points:
- web/index.html
- test/my_element_test.html
<!doctype html>
<html>
<head>
<title>My Element Test</title>
<link rel="import" href="packages/polymer_dart_testing/my_element.html">
</head>
<body>
<div>Custom HTML Test is Custom.</div>
<my-element></my-element>
<script type="application/dart" src="my_element_test.dart"></script>
</body>
</html>
import 'package:test/test.dart';
import 'package:polymer_dart_testing/my_element.dart';
import 'package:polymer/polymer.dart';
import 'dart:html';
main() {
setUp(() async {
await initPolymer();
return await Polymer.onReady;
});
test('custom_html_test', (){
expect(true, isTrue);
});
}
pub run test...
在启动Polymer并添加到pubspec
入口点时失败。$ pub serve
Loading source assets...
Loading polymer and test/pub_serve transformers...
Serving polymer_dart_testing web on http://localhost:8080
Serving polymer_dart_testing test on http://localhost:8081
Build completed successfully
...
...
/my_element_test.html.polymer.bootstrap.dart.browser_test.dart →
Could not find asset polymer_dart_testing|test/my_element_test.html.polymer.bootstrap.dart.browser_test.dart.
$ pub run test --pub-serve=8081 -p content-shell
"pub serve" is compiling test/my_element_test.dart...
00:00 +0: load error 00:00 +0 -1: load error
Failed to load "test/my_element_test.dart": Failed to load script at http://localhost:8081/my_element_test.html.polymer.bootstrap.dart.browser_test.dart.
00:00 +0 -1: Some tests failed.
答案 0 :(得分:5)
@whenPolymerReady
上的注释main()
丢失了。此外,应将测试变换器(在测试包的README.md中解释)添加到pubspec.yaml中的变换器部分。