我尝试测试一些组件: https://gist.github.com/Rasarts/000e233092b6781128a8488cbbb7a051
dependencies:
angular2: '^3.0.0-alpha+1'
angular2_components: '^0.4.0-alpha'
dev_dependencies:
angular_test:
git: "https://github.com/dart-lang/angular_test.git"
version: '^1.0.0-alpha+5'
test: '^0.12.20+2'
@Component(selector: 'page-view', templateUrl: 'page_view_component.html')
class PageViewComponent {}
@AngularEntrypoint()
void main() {
test('Should create a new component in the DOM', () async {
NgTestBed testBed = new NgTestBed<PageViewComponent>();
NgTestFixture fixture = await testBed.create();
expect(fixture.rootElement.innerHtml, contains("PageViewComponent"));
});
}
当我运行 pub run test -p dartium 命令时,我的测试失败了:
00:02 +0 -1: test/client/components/page_view_test.dart: Should create a new component in the DO
M [E]
Cannot find reflection information on ApplicationRefImpl
package:angular2/src/core/reflection/reflection.dart 24:7 NoReflectionCapabilities.factory
package:angular2/src/core/reflection/reflector.dart 85:37 Reflector.factory
package:angular2/src/core/di/reflective_provider.dart 130:27 resolveReflectiveFactory
package:angular2/src/core/di/reflective_provider.dart 156:8 resolveReflectiveProvider
dart:_internal ListIterable.toList
package:angular2/src/core/di/reflective_provider.dart 163:60 resolveReflectiveProviders
package:angular2/src/core/di/reflective_injector.dart 363:12 ReflectiveInjector.resolve
package:angular2/src/core/di/reflective_injector.dart 392:58 ReflectiveInjector.resolveAndCre
ate
package:angular_test/src/bootstrap.dart 35:42 bootstrapForTest
package:angular_test/src/frontend/bed.dart 192:14 NgTestBed._createDynamic.<fn>
dart:async Future.Future.sync
package:angular_test/src/frontend/bed.dart 190:16 NgTestBed._createDynamic
package:angular_test/src/frontend/bed.dart 171:12 NgTestBed.create
page_view_test.dart 17:43 main.<fn>.<async>
===== asynchronous gap ===========================
dart:async Future.Future.sync
package:angular_test/src/frontend/bed.dart 190:16 NgTestBed._createDynamic
package:angular_test/src/frontend/bed.dart 171:12 NgTestBed.create
page_view_test.dart 17:43 main.<fn>.<async>
===== asynchronous gap ===========================
dart:async Future.Future.microtask
page_view_test.dart main.<fn>
00:02 +0 -1: Some tests failed.
当我运行 pub run angular_test:test 时,我得到:
Could not find bin/test.dart in package angular_test.
当我运行 pub run angular_test 并打开Dartium时,在控制台中我得到:
00:00 [32m+0[0m: Should create a new component in the DOM[0m
(program):1 00:00 [32m+0[0m[31m -1[0m: Should create a new component in the DOM [1m[31m[E][0m[0m
(program):1 NoSuchMethodError: Class 'DynamicComponentLoaderImpl' has no instance method 'loadAsRootIntoNode'.
Receiver: Instance of 'DynamicComponentLoaderImpl'
Tried calling: loadAsRootIntoNode(Type: class 'PageViewComponent', Instance of 'ReflectiveInjectorImpl', overrideNode: Instance of 'HtmlElementImpl')
(program):1 dart:core Object.noSuchMethod
package:angular_test/src/bootstrap.dart 75:37 _runAndLoadComponent.<async>
dart:async _ZoneDelegate.run
package:angular2/src/core/zone/ng_zone.dart 176:21 NgZone._run
dart:async _CustomZone.bindCallback.<fn>
package:angular2/src/core/zone/ng_zone.dart 162:11 NgZone._scheduleMicrotask.<fn>
dart:async _ZoneDelegate.run
package:angular2/src/core/zone/ng_zone.dart 176:21 NgZone._run
===== asynchronous gap ===========================
dart:async _Completer.completeError
package:angular_test/src/bootstrap.dart 90:1 _runAndLoadComponent.<async>
dart:async _ZoneDelegate.run
package:angular2/src/core/zone/ng_zone.dart 176:21 NgZone._run
dart:async _CustomZone.bindCallback.<fn>
package:angular2/src/core/zone/ng_zone.dart 162:11 NgZone._scheduleMicrotask.<fn>
dart:async _ZoneDelegate.run
package:angular2/src/core/zone/ng_zone.dart 176:21 NgZone._run
===== asynchronous gap ===========================
dart:async Future.Future.microtask
package:angular_test/src/bootstrap.dart _runAndLoadComponent
package:angular_test/src/bootstrap.dart 47:12 bootstrapForTest.<fn>
package:angular2/src/core/application_ref.dart 314:26 ApplicationRefImpl.run.<fn>
dart:async _ZoneDelegate.run
package:angular2/src/core/zone/ng_zone.dart 176:21 NgZone._run
dart:async _CustomZone.run
package:angular2/src/core/zone/ng_zone.dart 305:23 NgZone.run
package:angular2/src/core/application_ref.dart 312:10 ApplicationRefImpl.run
package:angular_test/src/bootstrap.dart 46:17 bootstrapForTest
package:angular_test/src/frontend/bed.dart 192:14 NgTestBed._createDynamic.<fn>
dart:async Future.Future.sync
package:angular_test/src/frontend/bed.dart 190:16 NgTestBed._createDynamic
package:angular_test/src/frontend/bed.dart 171:12 NgTestBed.create
page_view_test.dart 17:43 main.<fn>.<async>
===== asynchronous gap ===========================
dart:async Future.Future.microtask
page_view_test.dart main.<fn>
(program):1 00:00 [32m+0[0m[31m -1[0m: [31mSome tests failed.[0m
(program):1
page_view_test.html:1 Uncaught Unhandled exception:
Dummy exception to set exit code.
#0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1138)
#1 _microtaskLoop (dart:async/schedule_microtask.dart:41)
#2 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#3 _ScheduleImmediateHelper._handleMutation (dart:html:49306)
page_view_test.html:1 Observatory listening at http://127.0.0.1:33685/
如何进行测试?
答案 0 :(得分:3)
尝试返回angular2版本3.0.0-alpha。 angular_test仍在进行中,需要更新才能使用3.0.0-alpha + 1。