Angular2 test error when bullying a service

Trying to test a component with service dependencies that support the shutdown API made a mock version of this service with a class that extends the real service.

Now, if I redefine the supplier with a laugh, a strange error arises from the karma reporter, first 404 for 2 non-existent files (which really should not exist), and then "{originalErr: {}}". I mean, at least tell me what I did wrong :)

My test suit:

 describe('App: HeaderComponent', () => {
      it('should get categories on initialization', 
        async(
          inject([TestComponentBuilder], (builder: TestComponentBuilder) => {
            let fixture: ComponentFixture<HeaderComponent>;
            expect(builder).toBeDefined();
            return builder
              .overrideProviders(HeaderComponent, [{provide: CategoryService, useClass: MockCategoryService}])
              .createAsync(HeaderComponent).then((_fixture) => {
                fixture = _fixture;
                let $el = fixture.debugElement;
                let el = $el.nativeElement;
                let component = $el.componentInstance;
                component.ngOnInit();
                fixture.detectChanges();
                expect(el.querySelector('a')).toHaveText('Electric');
              });
          })
        )
      );
    });

Conclusion:

01 08 2016 11:58:29.684:WARN [karma]: No captured browser, open http://localhost:9876/
01 08 2016 11:58:29.713:INFO [karma]: Karma v1.1.2 server started at http://localhost:9876/
01 08 2016 11:58:29.718:INFO [launcher]: Launching browser Chrome with unlimited concurrency
01 08 2016 11:58:29.729:INFO [launcher]: Starting browser Chrome
01 08 2016 11:58:32.277:INFO [Chrome 52.0.2743 (Windows 10 0.0.0)]: Connected on socket /#Semtu7s7yqM-TW0GAAAA with id 14496897
01 08 2016 11:58:35.315:WARN [web-server]: 404: /base/dist/app/shared/services.js
01 08 2016 11:58:35.318:WARN [web-server]: 404: /base/dist/app/shared/services/mocks.js
Chrome 52.0.2743 (Windows 10 0.0.0) ERROR
  {
    "originalErr": {}
  }

If I delete the line of the test pass (but does not execute the "then (...)" block

overrideProviders(HeaderComponent, [{provide: CategoryService, useClass: MockCategoryService}])

+4
source share
1

, - , , "ts", . - :

import { CategoryService } from '../../shared/services/category/category.service';
import { MockCategoryService } from '../../shared/services/category/category.service.mock';

import { CategoryService, MockCategoryService } from '../../shared/services/category';

index.ts , .

Wierd, Huh?

async- , ,

+1

Source: https://habr.com/ru/post/1649760/


All Articles