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

this.expiry.last is not a function #132

Open DaveTacker opened 4 years ago

DaveTacker commented 4 years ago

Describe the bug ERROR TypeError: this.expiry.last is not a function at Idle.push../node_modules/@ng-idle/core/fesm5/ng-idle-core.js.Idle.watch (ng-idle-core.js:1221)

To Reproduce app.module.ts

import { Idle, IdleExpiry } from '@ng-idle/core';

@NgModule({
  ...
  providers: [
    Idle,
    IdleExpiry
  ],
})
export class AppModule {}

app.component.ts

import { IdleService } from './Services/idle.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements AfterViewInit {
  constructor(private idleSvc: IdleService) {
      this.idleSvc.start();
  }
}

idle.service.ts

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

@Injectable({ providedIn: 'root' })
export class IdleService {
  public idleState = 'Not started.';

  constructor(private idle: Idle) {}

  public start(): void {
    this.idle.setIdle(5);
    // sets a timeout period of 5 seconds. after 10 seconds of inactivity, the user will be considered timed out.
    // this.idle.setTimeout(5);
    // sets the default interrupts, in this case, things like clicks, scrolls, touches to the document
    this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);

    this.idle.onIdleStart.subscribe(() => {
      this.idleState = 'You\'ve gone idle!';
      console.log(this.idleState);
    });

    this.idle.onTimeoutWarning.subscribe(countdown => {
      this.idleState = 'You will time out in ' + countdown + ' seconds!';
      console.log(this.idleState);
    });

    this.idle.watch();
    this.idleState = 'Started.';
  }
}

Expected behavior A timer starts that will reset upon user activity.

Please tell us about your environment

Additional context I followed the example as closely as I could to import the module into the project.

nimit199 commented 4 years ago

I am getting the same error when I try to Unit Test(jasmine) the component in which I have used Idle.

For now, do something like this https://stackoverflow.com/questions/43919222/mock-idle-in-angular-4-unit-tests

This will work

swapnil0545 commented 2 years ago

Even I m facing same issue. any alternative to mocking would be great.