Skip to content

Running ng test fails with Uncaught ReferenceError: [TYPE_NAME] is not defined #5651

@IngvarKofoed

Description

@IngvarKofoed

Bug Report or Feature Request (mark with an x)

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

Versions.

$ ng --version
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.0.0
node: 6.9.1
os: win32 x64
@angular/common: 4.0.0
@angular/compiler: 4.0.0
@angular/core: 4.0.0
@angular/forms: 4.0.0
@angular/http: 4.0.0
@angular/platform-browser: 4.0.0
@angular/platform-browser-dynamic: 4.0.0
@angular/router: 4.0.0
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.0

Windows 10

Repro steps.

Step 1
Run the following command

ng new myapp

Step 2
Add following file MyType.ts in the folder where the generate app.conponent.ts is located.

export class MyType {
    constructor(public id: string){}
}

Step 3
Modify app.conponent.ts so it looks like this:

import { Component, Input } from '@angular/core';
import { MyType } from "app/MyType";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app works!';

  private selectedId: string;
  @Input() set setSelectedId(myType: MyType | undefined) {
    if (product !== undefined) {
      this.selectedId = myType.id;
    }
    else {
      this.selectedId = myType;
    }
  }
}

Step 4
Run the following command

ng test

The log given by the failure.

Result:

$ ng test
25 03 2017 07:37:40.092:WARN [karma]: No captured browser, open http://localhost:9876/
25 03 2017 07:37:40.107:INFO [karma]: Karma v1.4.1 server started at http://0.0.0.0:9876/
25 03 2017 07:37:40.108:INFO [launcher]: Launching browser Chrome with unlimited concurrency
25 03 2017 07:37:40.185:INFO [launcher]: Starting browser Chrome
25 03 2017 07:37:41.275:INFO [Chrome 57.0.2987 (Windows 10 0.0.0)]: Connected on socket 9t52BW0h_NVdN1zYAAAA with id 31811334
Chrome 57.0.2987 (Windows 10 0.0.0) ERROR
  Uncaught ReferenceError: MyType_1 is not defined
  at webpack:///src/app/app.component.ts:13:43 <- src/test.ts:52770

Chrome 57.0.2987 (Windows 10 0.0.0) ERROR
  Uncaught ReferenceError: MyType_1 is not defined
  at webpack:///src/app/app.component.ts:13:43 <- src/test.ts:52770

Desired functionality.

I would like to to have the test being run :)

Mention any other details that might be useful.

App is working fine, so it seems to be only when running tests. I know that it worked in version 2.x of the cli and Im pretty sure it is related to the typescript version, where it worked with TS 2.0.x and not with TS 2.2.x.

Alto, it works if @Input is not used and app.component.ts looks this:

import { Component } from '@angular/core';
import { MyType } from "app/MyType";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app works!';

  private selectedId: string;
  set setSelectedId(myType: MyType | undefined) {
    if (product !== undefined) {
      this.selectedId = myType.id;
    }
    else {
      this.selectedId = myType;
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions