Angular 4 Karma component error due to CORS issue

when I start ng testI get this error (I use the standard setting c Karma) when trying to check the component:

XMLHttpRequest cannot load ng:///DynamicTestModule/FullModalHeaderComponent.ngfactory.js. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

How can I solve this problem?

code:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { FullModalHeaderComponent } from './full-modal-header.component';

describe('FullModalHeaderComponent', () => {
  let component: FullModalHeaderComponent;
  let fixture: ComponentFixture<FullModalHeaderComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [FullModalHeaderComponent]
    })
      .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(FullModalHeaderComponent);
    fixture.detectChanges();
  });

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

and

import { Component, Input } from '@angular/core';
import { ProcessingCenter, Publication } from '../../publications/model';

@Component({
  selector: 'gom-full-modal-header',
  templateUrl: './full-modal-header.component.html'
})
export class FullModalHeaderComponent {

  @Input('processingCenter') processingCenter: ProcessingCenter;
  @Input('publication') publication: Publication;
  @Input('title') title: string;

}

In addition, when you run tests with the ng test --sourcemaps=falseproblem disappears.

+6
source share

All Articles