question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

karma fails for Tour of Heroes tutorial, part 3, Multiple Components

See original GitHub issue

Continued from: https://github.com/angular/quickstart/pull/184

I cannot run npm test on the results of the Tour of Heroes tutorial, part 3, Multiple Components. It produces this error:

    Chrome 52.0.2743 (Mac OS X 10.11.6) AppComponent with TCB should instantiate component FAILED
[1]     Error: Template parse errors:
[1]     Can't bind to 'hero' since it isn't a known property of 'my-hero-detail'.
[1]     1. If 'my-hero-detail' is an Angular component and it has 'hero' input, then verify that it is part of this module.
[1]     2. If 'my-hero-detail' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message.
[1]      ("
[1]           </li>
[1]         </ul>
[1]         <my-hero-detail [ERROR ->][hero]="selectedHero"></my-hero-detail>
[1]       "): AppComponent@10:20

It seems to me that hero is a known property of my-hero-detail:

export class HeroDetailComponent {
  @Input()
  hero: Hero;
}

What am I missing?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

21reactions
psnidercommented, Aug 20, 2016

Found a solution!

Figuring perhaps the spec test needs to know about HeroDetailComponent, I modified app/app.component.spec.ts, by adding:

import { HeroDetailComponent } from './hero-detail.component';

and changing beforeEach() to include HeroDetailComponent in its declarations:

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [FormsModule],
      declarations: [AppComponent, HeroDetailComponent]
    });
  });

Please update the tutorial to include these changes.

8reactions
filipesilvacommented, Sep 22, 2016

The right solution is to configure your testing module correctly:

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [FormsModule],
      declarations: [AppComponent, HeroDetailComponent]
    });
  });

Tour of Heroes doesn’t talk about unit tests so it really doesn’t make sense to update it with these solutions. Instead, we have the testing chapter at https://angular.io/docs/ts/latest/guide/testing.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unit Testing Tour of Heroes: Hero Service | by Luke Lindner
This tutorial will take you through creating these tests for this application. You should be familiar with the basics of Karma and Jasmine,...
Read more >
Using Components - Angular Tour of Heroes Tutorial Part 2
Creating a Component in Angular - Using Components - Angular Tour of Heroes Tutorial Part 2. 2.9K views · 1 year ago ......
Read more >
Angular tour-of-heroes: no provider for HttpClient when testing ...
I'm new to Angular tests and this is quite annoying when you just try to run the ng test from the official tutorial...
Read more >
Testing Angular routing components with the ...
Angular testing with the RouterTestingModule (3 Part Series) ... for the DashboardComponent from the Tour of Heroes tutorial on Angular.io.
Read more >
Tour of Heroes application and tutorial - Angular
Try it now covers the same major topics —components, template syntax, routing, services, and accessing data using HTTP— in a condensed format, following...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found