Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: "component cannot define both template and templateUrl"

I have some karma/phantomjs tests that used to work but now give me this error for every component even though the components do not in fact define both template and templateUrl.

I don't know whether it's related but I am also getting many reports of this error:

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)

I noticed both at the same time but I had made a lot of changes without running tests very often.

If you can think of a possible solution or even a way to debug this kind of test in my kind of project, I would be very happy.

The repository is here

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

and the compiled js looks like

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;

The test log is 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
...

The error is thrown by 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`);
  }
...
like image 449
Dan Cancro Avatar asked Apr 20 '26 23:04

Dan Cancro


1 Answers

This was caused by a breaking change in Angular 4.1.3 and fixed with an update to jhipster tests by @sendikumarn

like image 62
Dan Cancro Avatar answered Apr 23 '26 16:04

Dan Cancro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!