Tests with Karma/Jasmin?
Opened this issue · 0 comments
Hello, i'am trying ti implement some tests, to test my implementation with ng-idle, but it fails:
Test-Code:
import { Router } from '@angular/router';
import {async} from '@angular/core/testing';
import { inject, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { TimeoutService } from './timeout.service';
import { CoreTestingModule } from '../../core-testing.module';
fdescribe('TimeoutService', () => {
let router: Router;
let service: TimeoutService;
const spies = {
navigate: null
};
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule, CoreTestingModule],
providers: [TimeoutService]
});
//spies.navigate = spyOn(router, 'navigate').and.stub();
service = TestBed.get(TimeoutService);
}));
fit('should navigate to index after 15 Seconds', () => {
service.setIdleTime(10);
service.setTimeoutTime(5);
console.log('TEST FINISHED');
//expect(spies.navigate).toHaveBeenCalledWith(['/index']);
});
});
My karma.conf.json
module.exports = function (config) {
config.set({
basePath: '..',
frameworks: ['jasmine', 'intl-shim', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-intl-shim'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-junit-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
files: [
'node_modules/intl/locale-data/jsonp/de-DE.js',
'node_modules/ng-idle/angular-idle.min.js'
],
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'),
reports: ['html', 'lcovonly', 'cobertura'],
fixWebpackSourcePaths: true
},
client: {
clearContext: true // leave Jasmine Spec Runner output visible in browser
},reporters: ['progress', 'kjhtml', 'junit'], port: 9876, colors: true, logLevel: config.LOG_ERROR, autoWatch: false, browsers: ['ChromeHeadlessNoSandbox'], customLaunchers: { ChromeHeadlessNoSandbox: { base: 'ChromeHeadless', flags: [ '--no-sandbox' ] } }, singleRun: true, browserNoActivityTimeout: 100000, restartOnFileChange: true });
};
But i get error:
Browserslist: caniuse-lite is outdated. Please run next command
npm update
HeadlessChrome 80.0.3987 (Windows 10.0.0) TimeoutService should navigate to index after 15 Seconds FAILED
StaticInjectorError(Platform: core)[TimeoutService -> Idle]:
NullInjectorError: No provider for Idle!
NullInjectorError: StaticInjectorError(DynamicTestModule)[TimeoutService -> Idle]:
at NullInjector.get (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:855:1)
at resolveToken (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:17513:1)
at tryResolveToken (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:17439:1)
at StaticInjector.get (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:17265:1)
at resolveToken (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:17513:1)
at tryResolveToken (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:17439:1)
at StaticInjector.get (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:17265:1)
at resolveNgModuleDep (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:30392:1)
at _createClass (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:30464:1)
at _createProviderInstance (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:30425:1)
TypeError: Cannot read property 'setIdleTime' of undefined
at Object. (http://localhost:9876/_karma_webpack_/src/core/services/timeout/timeout.service.spec.ts:26:17)
at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:359:1)
at ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:308:1)
at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:358:1)
at Zone.run (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:124:1)
at runInTestZone (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:561:1)
at Object. (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:576:1)
HeadlessChrome 80.0.3987 (Windows 10.0.0): Executed 1 of 478 (1 FAILED) (skipped 444) (0 secs / 0.213 secs)
How can i run tests of ng-idle with karma-jasmine?