ng2-idle
ng2-idle copied to clipboard
this.expiry.last is not a function
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.
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
Even I m facing same issue. any alternative to mocking would be great.