Angular 4 Unit test error - Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'ng:///DynamicTestModule/LoginComponent.ngfactory.js'

前端 未结 4 1700
花落未央
花落未央 2021-02-18 15:03

I am writing some unit tests for my component and i am getting this cryptic error message. I found a similar question at Angular 2 unit testing - getting error Failed to load &#

4条回答
  •  轮回少年
    2021-02-18 15:52

    Been chasing this for hours. Finally discovered that the problem was simply that I had imported HttpClientModule, but not HttpClient:

    import { HttpClient, HttpClientModule } from '@angular/common/http';

    All those CORS errors, and '[Script Loader]', DOMException{stack: 'Error: Failed to execute 'send' on 'XMLHttpRequest' stuff, and it came down to just not having HttpClient!

提交回复
热议问题