【发布时间】:2015-06-13 21:25:48
【问题描述】:
如何使用新的 test 库测试 Polymer 元素?
使用新的test 库来测试Dart Polymer 元素,我构建了my_element_test.html as prescribed。请查看我的仓库:polymer-dart-testing。
没有聚合物引发通过
my_element_test.html 和 my_element_test.dart(注释掉聚合物启动)按预期通过测试:
my_element_test.html
<!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>
my_element_test.dart
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... 的情况下在Dartium 中加载通过控制台并显示自定义元素,在将test/my_element_test.html 添加到pubspec.yaml 中的聚合物入口点之后。
pubspec.yaml
transformers:
- polymer:
entry_points:
- web/index.html
- test/my_element_test.html
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>
my_element_test.dart
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.
【问题讨论】:
标签: unit-testing testing dart dart-polymer