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

Example code tests timeout and fail #42

Open jessesanders opened 7 years ago

jessesanders commented 7 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

Following the example code at https://hackedbychinese.github.io/ng2-idle. When I run the tests, they timeout with this error:

Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

If I remove the call to this.idle.watch(), the tests don't timeout.

Expected behavior The tests should run and pass without timing out.

Minimal reproduction of the problem with instructions I create a new project with angular-cli (RC2), add the example code, validate the example works in the UI, run the tests using ng test, the tests now fail with a timeout.

What is the motivation / use case for changing the behavior? It would be nice to get the tests to work.

Please tell us about your environment: MAC Sierra

jessesanders commented 7 years ago

I can get the tests to work if I create a mock for the Idle class:

@Injectable()
export class IdleMock {
    private onIdleEnd = new EventEmitter();
    private onIdleStart = new EventEmitter();
    private onTimeout = new EventEmitter();
    private onTimeoutWarning = new EventEmitter();

    watch() {
    }

    setIdle() {
    }

    setTimeout() {
    }

    setInterrupts() {
    }
}

and then override the Idle class with the mock:

TestBed.configureTestingModule({
            declarations: [
                AppComponent
            ],
            imports: [
                NgIdleKeepaliveModule.forRoot()
            ],
            providers: [
                {provide: Idle, useClass: IdleMock}
            ]
        }).compileComponents();
messages2raja commented 4 years ago

Hi, It would be helpful if you can share the complete test file with some tests written