简体   繁体   中英

Why does Angular2 TestBed's compileComponents can't find my templates?

I have a component, let's call it MyComponent. It's using my.component.html as the templateUrl.

@Component({
  selector: "my-component",
  templateUrl: "./my.component.html",
  styleUrls: ["./my.component.css"]
})

I am writing a test (spec) for this component. Since, it'susing an external template, I am calling compileComponents after configureTestingModule .

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

While running the test, I am getting this error -

Failed to load my.component.html

The app runs absolutely okay with npm start and serve the templates as it should be. It's just the test which is failing with given setup. What I am doing wrong?

I am following this tutorial .

在我的 webpack 测试配置中,我只有awesome- typescript -loader ,我只需要添加angular2-template-loader

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM