The selector “#root0” dID not match any elements’ error.
测试代码:
@Component({ template: '',directives: [GroupBox,GroupBoxheader]})class TestComponent {}describe('group-Box control',() => { it('should show the Title',injectAsync([TestComponentBuilder],(tcb) => { return tcb.overrIDeTemplate(TestComponent,'<group-Box><group-Box-header>Title Content</group-Box-header></group-Box>') .createAsync(TestComponent).then( (fixture) => { fixture.detectChanges(); let compiled = fixture.deBUGElement.nativeElement; expect(compiled).toContainText('Title Content'); }); })); it('should show the body','<group-Box><group-Box-header>Title Content</group-Box-header>Body Content</group-Box>') .createAsync(TestComponent).then( (fixture) => { fixture.detectChanges(); let compiled = fixture.deBUGElement.nativeElement; expect(compiled).toContainText('Body Content'); }); }));});
我按照https://github.com/juliemr/ng2-test-seed的指导方针使用Karma和Jasmine
以下存储库重现错误:https://github.com/cangosta/ng2_testing_controls
堆栈跟踪:
解决方法 这在Angular 2.0.0-beta.3中得到修复14 01 2016 11:40:32.073:INFO [karma]: Karma v0.13.19 server started at 07002
14 01 2016 11:40:32.078:INFO [launcher]: Starting browser Chrome
14 01 2016 11:40:32.669:INFO [Chrome 47.0.2526 (windows 8.1 0.0.0)]: Connected on socket /#9hKZqsNbKFPfYWzIAAAA with ID 50428936
Chrome 47.0.2526 (windows 8.1 0.0.0) group-Box control should show the body Failed
Failed: The selector “#root0” dID not match any elements
Error: The selector “#root0” dID not match any elements
at new BaseException (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2.dev.Js:8080:21)
at Domrenderer_.createRootHostVIEw (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2.dev.Js:15248:15)
at AppVIEwManager_.createRootHostVIEw (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2.dev.Js:11265:52)
at C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2.dev.Js:14531:46
at Zone.run (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:138:17)
at Zone.run (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/testing.dev.Js:2544:30)
at zoneBoundFn (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:111:19)
at lib$es6$promise$$internal$$tryCatch (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:1511:16)
at lib$es6$promise$$internal$$invokeCallback (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:1523:17)
at lib$es6$promise$$internal$$publish (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:1494:11)
at C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:243:5
at microtask (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/testing.dev.Js:2557:15)
at Zone.run (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:138:17)
at Zone.run (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/testing.dev.Js:2544:30)
at zoneBoundFn (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:111:19)
at lib$es6$promise$asap$$flush (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:1305:9)
Failed: Cannot read property ‘hostVIEw’ of undefined
TypeError: Cannot read property ‘hostVIEw’ of undefined
at new ComponentFixture_ (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/testing.dev.Js:2047:97)
at C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/testing.dev.Js:2145:16
at Zone.run (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:138:17)
at Zone.run (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/testing.dev.Js:2544:30)
at zoneBoundFn (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:111:19)
at lib$es6$promise$$internal$$tryCatch (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:1511:16)
at lib$es6$promise$$internal$$invokeCallback (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:1523:17)
at lib$es6$promise$$internal$$publish (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:1494:11)
at C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:243:5
at microtask (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/testing.dev.Js:2557:15)
at Zone.run (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:138:17)
at Zone.run (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/testing.dev.Js:2544:30)
at zoneBoundFn (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:111:19)
at lib$es6$promise$asap$$flush (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:1305:9)
Failed: Cannot read property ‘detectChanges’ of undefined
TypeError: Cannot read property ‘detectChanges’ of undefined
at C:/Projectos/Fontes/Stratus-HTML/build/test/infrastructure/controls/group-Box.test.Js:52:20
at Zone.run (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:138:17)
at Zone.run (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/testing.dev.Js:2544:30)
at zoneBoundFn (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:111:19)
at lib$es6$promise$$internal$$tryCatch (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:1511:16)
at lib$es6$promise$$internal$$invokeCallback (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:1523:17)
at lib$es6$promise$$internal$$publish (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:1494:11)
at C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:243:5
at microtask (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/testing.dev.Js:2557:15)
at Zone.run (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:138:17)
at Zone.run (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/testing.dev.Js:2544:30)
at zoneBoundFn (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:111:19)
at lib$es6$promise$asap$$flush (C:/Projectos/Fontes/Stratus-HTML/build/assets/Js/angular2-polyfills.Js:1305:9)
Chrome 47.0.2526 (windows 8.1 0.0.0): Executed 59 of 60 (1 Failed) (skipped 1) (0.519 secs / 0.51 secs)
[11:40:33] ‘test’ errored after 2.01 s
[11:40:33] Error: 1
at formatError (C:\Users\LSANTOS\AppData\Roaming\npm\node_modules\gulp\bin\gulp.Js:169:10)
at Gulp. (C:\Users\LSANTOS\AppData\Roaming\npm\node_modules\gulp\bin\gulp.Js:195:15)
at emitOne (events.Js:77:13)
at Gulp.emit (events.Js:169:7)
at Gulp.orchestrator._emitTaskDone (C:\Projectos\Fontes\Stratus-HTML\node_modules\orchestrator\index.Js:264:8)
at C:\Projectos\Fontes\Stratus-HTML\node_modules\orchestrator\index.Js:275:23
at finish (C:\Projectos\Fontes\Stratus-HTML\node_modules\orchestrator\lib\runTask.Js:21:8)
at cb (C:\Projectos\Fontes\Stratus-HTML\node_modules\orchestrator\lib\runTask.Js:29:3)
at removeAllListeners (C:\Projectos\Fontes\Stratus-HTML\node_modules\karma\lib\server.Js:333:7)
at Server. (C:\Projectos\Fontes\Stratus-HTML\node_modules\karma\lib\server.Js:344:9)
at Server.g (events.Js:260:16)
at emitNone (events.Js:72:20)
at Server.emit (events.Js:166:7)
at emitCloseNT (net.Js:1518:8)
at doNTCallback1 (node.Js:418:9)
at process._tickCallback (node.Js:340:17)
有关详细信息,请参见https://github.com/angular/angular/issues/6483#issuecomment-179557485
Basically,what I had to do:
Manually add tyPings for jasmine with tsd install jasmine -so and add///<reference...
in the test files; Add this in my imports:
import {setBaseTestProvIDers} from 'angular2/testing';import { TEST_broWSER_PLATFORM_PROVIDERS,TEST_broWSER_APPliCATION_PROVIDERS} from 'angular2/platform/testing/browser';
Add this before my Component tests:
setBaseTestProvIDers(TEST_broWSER_PLATFORM_PROVIDERS,TEST_broWSER_APPliCATION_PROVIDERS);总结
以上是内存溢出为你收集整理的测试 – 间歇性错误:’失败:选择器“#root0”与任何元素都不匹配全部内容,希望文章能够帮你解决测试 – 间歇性错误:’失败:选择器“#root0”与任何元素都不匹配所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)