Skip to content

Cannot import json files when running ng test #6786

@pgrm

Description

@pgrm

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.1.3
node: 8.1.0
os: win32 x64
@angular/animations: 4.2.4
@angular/common: 4.2.4
@angular/compiler: 4.2.4
@angular/core: 4.2.4
@angular/flex-layout: 2.0.0-beta.8
@angular/forms: 4.2.4
@angular/http: 4.2.4
@angular/material: 2.0.0-beta.7
@angular/platform-browser: 4.2.4
@angular/platform-browser-dynamic: 4.2.4
@angular/router: 4.2.4
@angular/cli: 1.1.3
@angular/compiler-cli: 4.2.4

Repro steps.

import sampleData from './data.json';

// check if sampleData is undefined or not - in ng serve it has the correct value, in ng test it's undefined

You can see more details in this repo - https://github.com/pgrm/angular-bug-import-json

  • npm start - you should see the content of sample.json
  • npm test - the exception will be thrown that it's undefined (the exception is just there to demonstrate that it's undefined)

Desired functionality.

since I import the json file as a module, it should be imported the same way in tests, like it is done for the application to be served or compiled

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions