Can anyone help me why test is not executed.
I added spec file at: 'app/1st.spec.ts' as per angular.io testing web site.
describe('1st tests', () => {
it('true is true', () => expect(true).toBe(true));
});
karma run with no issue. Here is the result:
Chrome 55.0.2883 (Windows 10 0.0.0): Executed 0 of 0 ERROR (0.002 secs / 0 secs)
I don't know the reason why my project doesn't work but I tested in another new project and the unit test is executed. Please advice!
Here is my package.json. I am also using Angular Universal.
{
"name": "my-app",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"backend": "nodemon bin/server/index.js",
"compile": "node_modules/.bin/webpack",
"dump-task-list": "npm run compile && node bin/server/index.js dump-task-list",
"server": "npm run compile && npm run backend",
"server-host": "ng build && ts-node server/server.ts",
"start": "npm run start-with-server",
"start-with-server": "npm run dump-task-list && ng serve",
"lint": "tslint \"src/**/*.ts\" \"log-server/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/core": "2.0.0",
"@angular/forms": "2.0.0",
"@angular/http": "2.0.0",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "3.0.0",
"@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.13",
"@ngrx/core": "^1.2.0",
"@ngrx/effects": "^2.0.0",
"@ngrx/store": "^2.2.1",
"@ngrx/store-devtools": "^3.1.0",
"@ngrx/store-log-monitor": "^3.0.2",
"@progress/kendo-angular-buttons": "^0.13.4",
"@progress/kendo-angular-grid": "^0.6.3",
"@progress/kendo-angular-upload": "^0.10.4",
"@progress/kendo-data-query": "^0.1.7",
"@telerik/kendo-theme-bootstrap": "^0.10.0",
"@types/winston": "0.0.32",
"angular2-express-engine": "^2.0.11",
"angular2-platform-node": "~2.0.11",
"angular2-universal": "^2.0.11",
"angular2-universal-polyfills": "^2.0.11",
"body-parser": "^1.15.2",
"bootstrap": "^4.0.0-alpha.5",
"cheerio": "^0.22.0",
"cookie-parser": "^1.4.3",
"core-js": "^2.4.1",
"express": "^4.14.0",
"jsnlog": "^2.20.1",
"node-uuid": "^1.4.7",
"pouchdb": "^6.0.7",
"preboot": "^4.5.2",
"rxjs": "5.0.0-beta.12",
"signalr": "^2.2.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.6.23"
},
"devDependencies": {
"@angularclass/resolve-angular-routes": "^1.0.9",
"@types/body-parser": "0.0.29",
"@types/chai": "^3.4.34",
"@types/cheerio": "^0.17.31",
"@types/compression": "0.0.29",
"@types/cookie-parser": "^1.3.30",
"@types/express": "^4.0.32",
"@types/express-serve-static-core": "^4.0.33",
"@types/hammerjs": "^2.0.32",
"@types/jasmine": "^2.2.30",
"@types/mime": "0.0.28",
"@types/mkdirp": "^0.3.29",
"@types/morgan": "^1.7.32",
"@types/node": "^6.0.38",
"@types/pouchdb": "^5.4.28",
"@types/serve-static": "^1.7.27",
"@types/uuid": "^2.0.29",
"angular-cli": "1.0.0-beta.16",
"angular2-schema-form": "1.0.0-alpha.32",
"angular2-template-loader": "^0.4.0",
"codelyzer": "~0.0.26",
"concurrently": "^3.1.0",
"imports-loader": "^0.6.5",
"jasmine-core": "2.4.1",
"jasmine-spec-reporter": "2.5.0",
"json-loader": "^0.5.4",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"nodemon": "^1.10.0",
"protractor": "4.0.9",
"raw-loader": "^0.5.1",
"rimraf": "^2.5.4",
"string-replace-loader": "github:gdi2290/string-replace-loader",
"ts-loader": "^0.8.2",
"ts-node": "1.2.1",
"tslint": "3.13.0",
"typescript": "2.0.2",
"webpack": "2.1.0-beta.22",
"winston": "^2.3.0",
"winston-daily-rotate-file": "^1.3.1"
}
}
Here is my karma.config
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', 'angular-cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-remap-istanbul'),
require('angular-cli/plugins/karma')
],
files: [
{ pattern: './src/test.ts', watched: false }
],
preprocessors: {
'./src/test.ts': ['angular-cli']
},
remapIstanbulReporter: {
reports: {
html: 'coverage',
lcovonly: './coverage/coverage.lcov'
}
},
angularCli: {
config: './angular-cli.json',
environment: 'dev'
},
reporters: ['progress', 'karma-remap-istanbul'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
here is test.ts
import './polyfills.ts';
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
declare var __karma__: any;
declare var require: any;
// Prevent Karma from running prematurely.
__karma__.loaded = function () {};
Promise.all([
System.import('@angular/core/testing'),
System.import('@angular/platform-browser-dynamic/testing'),
])
// First, initialize the Angular testing environment.
.then(([testing, testingBrowser]) => {
testing.getTestBed().initTestEnvironment(
testingBrowser.BrowserDynamicTestingModule,
testingBrowser.platformBrowserDynamicTesting()
);
})
// Then we find all the tests.
.then(() => require.context('./', true, /\.spec\.ts/))
// And load the modules.
.then(context => context.keys().map(context))
// Finally, start Karma to run the tests.
.then(__karma__.start, __karma__.error);
1st.spec.ts, and in config it istest.ts.1st.spec.tsshould be executed.filesis the place where specs that should be executed are specified, and in your case it appears like they are not. This is the only (and very substantial) clue on the possible problem that the question has. If you can't provide a reproducible example of the problem, I'm afraid nothing else can be done here.