Skip to content

Can't compile test: Possible issue with my setup? #56

@AleskiWeb

Description

@AleskiWeb

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);
    })
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions