错误:"组件无法定义模板和templateUrl"

时间:2017-05-19 05:03:34

标签: angular jasmine phantomjs karma-runner jhipster

我有一些karma / phantomjs测试曾经工作但现在给我每个组件的这个错误,即使组件实际上没有定义模板和templateUrl。

我不知道它是否相关,但我也收到很多关于此错误的报告:

Error: <spyOn> : could not find an object to spy upon for find()
Usage: spyOn(<object>, <methodName>) in /Users/Dan/work/bernierebuttals/gba/node_modules/jasmine-core/lib/jasmine-core/jasmine.js (line 4304)

我同时注意到了两个,但是我经常进行很多修改而不经常运行测试。

如果你能想到一个可能的解决方案,甚至是在我的项目中调试这种测试的方法,我会非常高兴。

存储库为here

...
@Component({
    selector: 'jhi-activate',
    templateUrl: './activate.component.html'
})
export class ActivateComponent implements OnInit {
...

并且编译的js看起来像

ActivateComponent = __decorate([
    core_1.Component({
        selector: 'jhi-activate',
        template: __webpack_require__("./src/main/webapp/app/account/activate/activate.component.html")
    }),
    __metadata("design:paramtypes", [activate_service_1.Activate,
        shared_1.LoginModalService,
        router_1.ActivatedRoute])
], ActivateComponent);
exports.ActivateComponent = ActivateComponent;

测试日志为here

...
PhantomJS 2.1.1 (Mac OS X 0.0.0) Component Tests ActivateComponent calls activate.get with the key from params FAILED
    Failed: 'ActivateComponent' component cannot define both template and templateUrl
    normalizeTemplate@spec/entry.ts:62868:209
    _loadDirectiveMetadata@spec/entry.ts:63811:92
    spec/entry.ts:64007:76
    forEach@[native code]
    loadNgModuleDirectiveAndPipeMetadata@spec/entry.ts:64006:48
    spec/entry.ts:75202:94
...

this line of Angular code

引发错误
...
if (prenormData.template != null) {
  if (prenormData.templateUrl != null) {
    throw syntaxError(
        `'${stringify(prenormData.componentType)}' component cannot define both template and templateUrl`);
  }
...

1 个答案:

答案 0 :(得分:2)

这是由Angular 4.1.3中的重大变化引起的,并且update通过@sendikumarn到jhipster测试修正了