Angular2 and Karma Issue

拈花ヽ惹草 提交于 2019-12-24 00:44:33

问题


I have a problem with tests - when running multiple tests one of them fails, but when I isolate them and run one at the time, they all pass. Tests are basic placeholders (I'm working on seed project) and typically look like this:

import {inject, injectAsync, TestComponentBuilder, beforeEachProviders} from 'angular2/testing'
import {describe, ddescribe, it, iit, expect} from 'angular2/testing'
import {provide} from 'angular2/core'
import {PeopleComponent} from './people.component'

describe('PeopleComponent', () => {
  beforeEachProviders(() => []);
  it('should ...', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
    return tcb.createAsync(PeopleComponent).then((fixture) => {
      fixture.detectChanges();
    });
  }));
});

When I change describe to ddescribe in any of the tests, they pass. I can't figure out why. Any ideas?

Full Error trace is below:

Chrome 47.0.2526 (Windows 10 0.0.0) DebugDirective should compile in component template FAILED
    Failed: The selector "#root0" did not match any elements
    Error: The selector "#root0" did not match any elements
        at new BaseException (C:/~/node_modules/angular2/bundles/angular2.dev.js:8080:21)
        at DomRenderer_.createRootHostView (C:/~/node_modules/angular2/bundles/angular2.dev.js:15248:15)
        at AppViewManager_.createRootHostView (C:/~/node_modules/angular2/bundles/angular2.dev.js:11265:52)
        at C:/~/node_modules/angular2/bundles/angular2.dev.js:14531:46
        at Zone.run (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:138:17)
        at Zone.run (C:/~/node_modules/angular2/bundles/testing.dev.js:2544:30)
        at zoneBoundFn (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:111:19)
        at lib$es6$promise$$internal$$tryCatch (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:1511:16)
        at lib$es6$promise$$internal$$invokeCallback (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:1523:17)
        at lib$es6$promise$$internal$$publish (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:1494:11)
        at C:/~/node_modules/angular2/bundles/angular2-polyfills.js:243:5
        at microtask (C:/~/node_modules/angular2/bundles/testing.dev.js:2557:15)
        at Zone.run (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:138:17)
        at Zone.run (C:/~/node_modules/angular2/bundles/testing.dev.js:2544:30)
        at zoneBoundFn (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:111:19)
        at lib$es6$promise$asap$$flush (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:1305:9)
    Failed: Cannot read property 'hostView' of undefined
    TypeError: Cannot read property 'hostView' of undefined
        at new ComponentFixture_ (C:/~/node_modules/angular2/bundles/testing.dev.js:2047:97)
        at C:/~/node_modules/angular2/bundles/testing.dev.js:2145:16
        at Zone.run (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:138:17)
        at Zone.run (C:/~/node_modules/angular2/bundles/testing.dev.js:2544:30)
        at zoneBoundFn (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:111:19)
        at lib$es6$promise$$internal$$tryCatch (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:1511:16)
        at lib$es6$promise$$internal$$invokeCallback (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:1523:17)
        at lib$es6$promise$$internal$$publish (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:1494:11)
        at C:/~/node_modules/angular2/bundles/angular2-polyfills.js:243:5
        at microtask (C:/~/node_modules/angular2/bundles/testing.dev.js:2557:15)
        at Zone.run (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:138:17)
        at Zone.run (C:/~/node_modules/angular2/bundles/testing.dev.js:2544:30)
        at zoneBoundFn (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:111:19)
        at lib$es6$promise$asap$$flush (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:1305:9)
    Failed: Cannot read property 'detectChanges' of undefined
    TypeError: Cannot read property 'detectChanges' of undefined
        at C:/~/dist/scripts/core/components/people/people.component.spec.js:17:32
        at C:/~/dist/scripts/core/components/people/people.component.spec.js:17:32
        at Zone.run (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:138:17)
        at Zone.run (C:/~/node_modules/angular2/bundles/testing.dev.js:2544:30)
        at zoneBoundFn (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:111:19)
        at lib$es6$promise$$internal$$tryCatch (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:1511:16)
        at lib$es6$promise$$internal$$invokeCallback (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:1523:17)
        at lib$es6$promise$$internal$$publish (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:1494:11)
        at C:/~/node_modules/angular2/bundles/angular2-polyfills.js:243:5
        at microtask (C:/~/node_modules/angular2/bundles/testing.dev.js:2557:15)
        at Zone.run (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:138:17)
        at Zone.run (C:/~/node_modules/angular2/bundles/testing.dev.js:2544:30)
        at zoneBoundFn (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:111:19)
        at lib$es6$promise$asap$$flush (C:/~/node_modules/angular2/bundles/angular2-polyfills.js:1305:9)
Chrome 47.0.2526 (Windows 10 0.0.0): Executed 16 of 16 (1 FAILED) (0.396 secs / 0.167 secs)

来源:https://stackoverflow.com/questions/34486476/angular2-and-karma-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!