我开始测试我的web组件,并注意到Dart有一个很好的库,并且它与Dart一起运行得很好。但是现在我也想测试我的聚合物成分,但是我很难做到这一点。似乎我的单元测试不承认我的元素是一个聚合物元素。现在我的“测试”是这样的
test.dart
import "../../../components/medium/bar-chart.dart";
import "package:unittest/unittest.dart";
import 'package:polymer/polymer.dart';
import 'dart:html';
main() {
// initPolymer();
print("--- Bar Chart Test ---");
group('Bar Chart Test', () {
test(("queryForBarChart"),() {
expect(querySelector('bar-chart'), isNotNull); // PASS
});
test(("testtest"),() {
// This should pass
expect(querySelector('bar-chart').test(), equals(5));
// Test failed: Caught type 'HtmlElement' is not a subtype of type 'BarChartElement' in type cast.
// without Cast: Test failed: Caught Class 'HtmlElement' has no instance method 'test'.
});
});
}test.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Unit Test Results</title>
<script src="../packages/web_components/platform.js"></script>
<link rel="import" href="packages/polymer/polymer.html"/>
<link rel="import" href="../../../components/medium/bar-chart.html"/>
<script src="../packages/browser/dart.js"></script>
<script type="application/dart" src="test.dart"></script>
</head>
<body
<bar-chart></bar-chart>
</body>
</html>另外,我得到了一个例外:
Uncaught :未能在'appendChild‘上执行’appendChild‘:类型'HTML’的节点可能不会插入到'#document‘类型的节点中。
来自: polymer.concat.js:6313
由于我没有测试飞镖聚合物的经验,所以我接受任何最好的建议。
发布于 2014-12-10 15:09:06
你需要适当的聚合物初始化代码。详情请参见how to implement a main function in polymer apps。
此包包含许多Polymer.dart单元测试,可以用作示例https://github.com/dart-lang/core-elements/tree/master/test。
import "../../../components/medium/bar-chart.dart";
import "package:unittest/unittest.dart";
import 'package:polymer/polymer.dart';
import 'dart:html';
main() {
// old initPolymer().run(() {
initPolymer().then((zone) => zone.run(() {
print("--- Bar Chart Test ---");
group('Bar Chart Test', () {
test(("queryForBarChart"),() {
expect(querySelector('bar-chart'), isNotNull); // PASS
});
test(("testtest"),() {
// This should pass
expect(querySelector('bar-chart').test(), equals(5));
// Test failed: Caught type 'HtmlElement' is not a subtype of type 'BarChartElement' in type cast.
// without Cast: Test failed: Caught Class 'HtmlElement' has no instance method 'test'.
});
});
});
}提示:不要忘记将测试的条目页添加到聚合物变压器配置中。
https://stackoverflow.com/questions/27404245
复制相似问题