karma-typescript-preprocessor
karma-typescript-preprocessor copied to clipboard
Can't compile test: Possible issue with my setup?
I can't get a simple test to work. Can you let me know of any reason the following shouldn't work? The error I receive is SyntaxError: Unexpected token 'const' on line 3 of my compiled test. I am just running the test with karma start
...is there a way to leave the test so I can read it?
main.ts file:
export default class Main {
constructor() {
this.testFunction();
}
addOne (x) {
x = x + 1;
return x;
}
}
karma.conf.js file:
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'**/*.ts': ['typescript']
},
// typescript preprocessor definition and config
typescriptPreprocessor: {
//options passed to the typescript compiler
options: {
target: 'es5',
module: 'system',
noImplicitAny: true,
sourceMap: false,
emitDecoratorMetadata: true,
experimentalDecorators: true,
noResolve: true,
concatenateOutput: false
},
// transforming the filenames
transformPath: function(path) {
return path.replace(/\.ts$/, '.js');
}
},
main-controller-spec.ts file:
/// <reference path="../../../../typings/karma-jasmine/karma-jasmine.d.ts" />
import Main from '../../../../src/app/main/controllers/main';
describe('quick test of tests :D', () => {
let main;
beforeEach(() => {
main = new Main();
})
it('should run the function from above', () => {
var x = 2;
spyOn(main, 'addOne');
main.addOne(x);
expect(main.addOne).toHaveBeenCalledWith(2);
})
})
Great to see the community lent you a hand on this :(. Did you managed to get this resolved? Suffering from similar isssue...