moribvndvs / ng2-idle

Responding to idle users in Angular (not AngularJS) applications.
https://moribvndvs.github.io/ng2-idle
Apache License 2.0
315 stars 128 forks source link

Tests won't load after Angular 6 upgrade #101

Closed nallarv closed 6 years ago

nallarv commented 6 years ago

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/HackedByChinese/ng2-idle/blob/master/CONTRIBUTING.md#getting-help

Current behavior Tests are not getting executed after angular 6 upgrade with the latest ngIdle module. Currently we see a Executed 0 of 0 ERROR (0.005 secs / 0 secs) message as soon as I add ngIdle to the constructor of any component or service. The whole test run itself fails without any message.

Expected behavior Tests should work fine or at least be able to load and report what the error is.

Minimal reproduction of the problem with instructions Create a brand new Angular 6 app using angular cli and add ngIdle to the constructor. The tests won't execute after that.

Please tell us about your environment: Mac OS - 10.12.6 Chrome - 66.0.3359

nallarv commented 6 years ago

Here is how my code looks. As simple as it can get. app.component.ts

import { Component } from '@angular/core';
import { DEFAULT_INTERRUPTSOURCES, Idle } from '@ng-idle/core';

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

  }
}

app.component.spec.ts


import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { Idle } from '@ng-idle/core';

describe('AppComponent', () => {
  const idle = {
    setIdle: jasmine.createSpy('idle'),
    setTimeout: jasmine.createSpy('setTimeout'),
    setInterrupts: jasmine.createSpy('setInterrupts')
  };
  beforeEach(async(() => {
    TestBed.configureTestingModule({

      declarations: [
        AppComponent
      ],
      providers: [{ provide: Idle, useValue: idle }]
    }).compileComponents();
  }));
  it('should create the app', async(() => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.debugElement.componentInstance;
    expect(app).toBeTruthy();
  }));
  it("should have as title 'app'", async(() => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.debugElement.componentInstance;
    expect(app.title).toEqual('app');
  }));
  it('should render title in a h1 tag', async(() => {
    const fixture = TestBed.createComponent(AppComponent);
    fixture.detectChanges();
    const compiled = fixture.debugElement.nativeElement;
    expect(compiled.querySelector('h1').textContent).toContain('Welcome to test-angular6-app2!');
  }));
});

`
dreamid27 commented 6 years ago

Will this package be supported angular v6?

slashinski commented 6 years ago

I have the same issue and have pinned my version down until this gets fixed. Any updates on this would be greatly appreciated.

dspies commented 6 years ago

I am having this issue as well, and I believe this is related to issue #99. I commented out import 'zone.js' from the pre>node_modules/@ng-idle/core/src/interruptsource.js</pre and my tests began running again.

nallarv commented 6 years ago

@dspies, Yup. That worked. Surprising that it fails so silently. @HackedByChinese, could you please take a look at this PR and merge it if all is fine?

moribvndvs commented 6 years ago

Duplicate of #99