angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng test "Cannot find name 'Event'." with live reload

Open eronalves opened this issue 9 years ago • 4 comments

- [ x ] bug report 
- [ ] feature request

Versions.

@angular/cli: 1.0.0 node: 7.0.0 os: darwin x64 npm: 4.2.0 OS: macOS Sierra.

Dependencies:

"@angular/animations": "^4.0.1",
"@angular/common": "^4.0.1",
"@angular/compiler": "^4.0.1",
"@angular/compiler-cli": "^4.0.1",
"@angular/core": "^4.0.1",
"@angular/forms": "^4.0.1",
"@angular/http": "^4.0.1",
"@angular/platform-browser": "^4.0.1",
"@angular/platform-browser-dynamic": "^4.0.1",
"@angular/platform-server": "^4.0.1",
"@angular/router": "^4.0.1"

Devdependencies:

"@angular/cli": "1.0.0",
"@angular/compiler-cli": "^4.0.1",
"@types/core-js": "^0.9.41",
"@types/jasmine": "2.5.47",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^0.2.0",
"karma-istanbul-threshold": "^1.2.2",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"pre-commit": "^1.2.2",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.4.2",
"typescript": "^2.2.2"

Repro steps.

I've a Karma test with new Event to update my inputs:

 it('Deve subtmeter o formulário', <any>fakeAsync((): void => {
    setInputValue('input[name="login"]', 'teste');
    setInputValue('input[name="password"]', '12345678');

    spyOn(component, 'login');
    const form = fixture.debugElement.query(By.css('form'));
    form.triggerEventHandler('submit', null);
    fixture.detectChanges();

    fixture.whenStable().then(() => {
      expect(component.login).toHaveBeenCalledTimes(1);
    });

  }));

  function setInputValue(selector: string, value: string) {
    fixture.detectChanges();
    tick();

    const input = fixture.debugElement.query(By.css(selector)).nativeElement;;
    input.value = value;
    input.dispatchEvent(new Event('input'));
    tick();
  }

The log given by the failure.

When I run ng test it works correctly, but when I modify any file and the live reload compiles my app again, the cli returns the message:

Cannot find name 'Event'.

My tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "target": "es5",
     "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

Desired functionality.

I don't know what is going on because only occurred when the app compiles with live reload. Do I need to configure the types of jasmine in another way?

Thanks!

eronalves avatar Apr 17 '17 20:04 eronalves

Heya, it looks like you updated your project to 1.0.0 but didn't follow the steps in https://github.com/angular/angular-cli/wiki/stories-1.0-update (especially the ones in the One tsconfig per app section). You might have some problem with your tsconfigs, where the ones used by unit tests aren't picking up the dom library.

filipesilva avatar May 05 '17 11:05 filipesilva

@filipesilva : I have verified the One tsconfig per app section, but still the same problem.

anilkhichar avatar May 10 '17 15:05 anilkhichar

I don't have this issue while using @angular/cli: 1.0.4. Due to few days back's dependency issue, I upgraded my project to @angular/cli: 1.3.0-rc.1 with @angular/xxxx: ~4.0.2. Then ng test is showing the same errors. ng test --watch false has no problems.

chouclee avatar Jul 28 '17 08:07 chouclee

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.