Frank Mehlhop
Frank Mehlhop

Reputation: 2222

Angular Karma not running all unit tests

I wrote two unittests but there are not executed. Please see the two screen shots below.

What is wrong, why it is not executed?

As you can read I get the message: "executed 45 of 47" Means also, the test are found, just not executed. How can it be?

Frank

@Terminal

@Karma

describe('LanguageSelectorComponent', () => {
  let component: LanguageSelectorComponent;
  let fixture: ComponentFixture<LanguageSelectorComponent>;
  let find: any;

  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [LanguageSelectorComponent],
      imports: [DxModule, RouterTestingModule],
      providers: [HttpClient, HttpHandler, NGXLogger, LanguageSelectorService]
    });

    fixture = TestBed.overrideComponent(LanguageSelectorComponent, {
      set: {
        providers: [{ provide: LanguageSelectorService, useClass: MockLanguageSelectorService }]
      }
    }).createComponent(LanguageSelectorComponent);
    fixture.detectChanges();
    component = fixture.componentInstance;
    find = (de => selector => de.query(By.css(selector)))(fixture.debugElement);
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should create dx select box', () => {
    expect(find('dx-select-box')).toBeDefined();
  });
});

Upvotes: 4

Views: 3590

Answers (2)

Frank Mehlhop
Frank Mehlhop

Reputation: 2222

The solution is not to find in my code above. My languageSelectorService was including a cookieStoreService and there was a mismatch while building the app. I moved the cookieStoreService into the component and now it works.

Thanks to Amit for your lines! (I learned about fdescribe.)

Frank

Upvotes: 0

Amit Chigadani
Amit Chigadani

Reputation: 29705

You can run only few test cases as you wish using karma-jasmine. This is possible either by prefixing describe with f (stands for focus) as fdescribe or it as fit.

fdescribe runs all the test specs implemented within that component. fit runs only that particular test spec. It is possible to do fit on multiple test specs which will run multiple test scpes ignoring the others.

To exclude few test specs or the entire component use xit or xdescribe respectively.

Please look at your specs for these special key words. Your problem might get solved.

Upvotes: 2

Related Questions