Skip to content

Karma not serving assets in angular 8 #14593

@plchampigny

Description

@plchampigny

🐞 bug report

Affected Package

Karma tests (ng t)

Is this a regression?

Yes, in version 7 it was working

Description

When loading a http asset, angular 8 returns
Failed: Http failure response for http://localhost:9877/assets/test.json: 404 Not Found

🔬 Minimal Reproduction

ng new ng8-test-assets

create a file in the assets folder named test.json with this content

{
  "test": true
}

in app.component.spec.ts:

  it('should get test.json', async () => {
    const client: HttpClient = TestBed.get(HttpClient);

    try {
      const result = await client.get('/assets/test.json').toPromise();
    } catch (err) {
      fail(err);
    }

  });

Heres a link to a repo with the issue:
https://github.com/plchampigny/ng8-test-assets

🔥 Exception or Error

Failed: Http failure response for http://localhost:9877/assets/test.json: 404 Not Found

🌍 Your Environment

Angular Version:

Angular CLI: 8.0.0
Node: 10.16.0
OS: win32 x64
Angular: 8.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.0
@angular-devkit/build-angular     0.800.0
@angular-devkit/build-optimizer   0.800.0
@angular-devkit/build-webpack     0.800.0
@angular-devkit/core              8.0.0
@angular-devkit/schematics        8.0.0
@ngtools/webpack                  8.0.0
@schematics/angular               8.0.0
@schematics/update                0.800.0
rxjs                              6.4.0
typescript                        3.4.5
webpack                           4.30.0

Anything else relevant?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions