Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this.expiry.last is not a function #132

Open
DaveTacker opened this issue Sep 17, 2019 · 2 comments
Open

this.expiry.last is not a function #132

DaveTacker opened this issue Sep 17, 2019 · 2 comments
Labels

Comments

@DaveTacker
Copy link

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

  • Mobile or Desktop: Desktop
  • Browser: Chrome
  • Version: 76.0.3809.132 (Official Build) (64-bit)
  • Angular version: 8.2.2
  • NodeJS version: 8.12.0
  • Language (TypeScript x.x, ES5, ES2015, etc.): TypeScript

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

@DaveTacker DaveTacker added the bug label Sep 17, 2019
@nimit199
Copy link

nimit199 commented Dec 16, 2019

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants