so I have been looking into this for some days now and didnt get anything to work. The problem is, that i cant require or import anything with my project.
Here my Test
import {App} from '../../app/spacken.component';
//var App = require('../../app/spacken.component');
describe('App', () => {
alert("1");
beforeEach(function() {
alert("2");
//this.app = /*null;*/new App();
});
it('should have name property', function() {
alert("3");
expect(/*this.app.name*/'John').toBe('John');
});
it('should say hello with name property', function() {
alert("4");
expect(this.app.sayHello('John')).toBe('Hello John');
});
});
Here my component
import {Component} from '@angular/core';
@Component({
selector: 'app',
template: '<span></span>'
})
export class App {
private name: string = 'John';
sayHello(): string {
return `Hello ${this.name}`;
}
}
Here my karma config
module.exports = function(config) {
var appBase = 'app/';
var backBase = 'backend/';
var cssBase = 'css/';
var testBase = 'tests/';
config.set({
basePath: '',
frameworks: [ 'jasmine' ],
plugins: [
require('karma-webpack'),
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-htmlfile-reporter')
],
browserNoActivityTimeout: 10000,
customLaunchers: {
// From the CLI. Not used here but interesting
// chrome setup for travis CI using chromium
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
files: [
//file
{pattern: appBase + '*.ts', included: false, watched:true},
{pattern: appBase + '**/*.ts', included: false, watched:true},
{pattern: backBase + '*.js', included: false, watched:true},
{pattern: backBase + '**/*.js', included: false, watched:true},
{pattern: cssBase + '*.css', included: false, watched:false},
{pattern: testBase + '**/*.ts', included: true, watched:true},
// System.js for module loading
'node_modules/systemjs/dist/system.src.js',
// Polyfills
'node_modules/core-js/client/shim.js',
'node_modules/reflect-metadata/Reflect.js',
// zone.js
'node_modules/zone.js/dist/zone.js',
'node_modules/http://ift.tt/1KReNIi',
'node_modules/http://ift.tt/2c7PMID',
'node_modules/http://ift.tt/2cGDBrq',
'node_modules/http://ift.tt/1KReLA0',
'node_modules/http://ift.tt/2anIl3w',
'node_modules/http://ift.tt/2b8mEkP',
// RxJs
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
// Paths loaded via module imports:
// Angular itself
{pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
{pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false},
{pattern: 'systemjs.config.js', included: false, watched: false},
{pattern: 'systemjs.config.js', included: false, watched: false},
'karma-test-shim.js'
],
preprocessors: {
// add webpack as preprocessor
'tests/**/*.ts': ['webpack']
},
webpack: {
// karma watches the test entry points
// (you don't need to specify the entry option)
// webpack watches dependencies
// webpack configuration
},
webpackMiddleware: {
// webpack-dev-middleware configuration
// i. e.
stats: 'errors-only'
},
// Proxied base paths for loading assets
proxies: {
// required for component assets fetched by Angular's compiler
},
exclude: [],
reporters: ['progress', 'html'],
// HtmlReporter configuration
htmlReporter: {
// Open this file to see results in browser
outputFile: '_test-output/tests.html',
// Optional
pageTitle: 'Unit Tests',
subPageTitle: __dirname
},
resolve: {
extensions: ['', '.js', '.ts']
},
port: 9001,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
})
}
I hope you can finde my mistake and show me what to do.
Aucun commentaire:
Enregistrer un commentaire