wallabyjs / public

Repository for Wallaby.js questions and issues
http://wallabyjs.com
760 stars 45 forks source link

I got import is unexpected when I run my unit test case using karma #566

Closed piyush-avantsoft closed 8 years ago

piyush-avantsoft commented 8 years ago

greeter.js

interface IPerson {
    getFullName() : string;
}

class Person implements IPerson {

    private firstName: string;
    private lastName: string;

    setFirstName(value: string) {
        this.firstName = value;
    }

    setLastName(value: string) {
        this.lastName = value;
    }

    getFullName(lastNameFirst: boolean = false): string {
        if (lastNameFirst) {
            return this.lastName + ", " + this.firstName; 
        }
        return this.firstName + ", " + this.lastName;
    }
}

karma.conf.js

// Karma configuration
// Generated on Tue Apr 26 2016 15:52:55 GMT+0530 (India Standard Time)

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],

    // list of files / patterns to load in the browser
    files: [
      'test/*.js'
    ],

    // list of files to exclude
    exclude: [
    ],

    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },

    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],

    // web server port
    port: 9876,

    // enable / disable colors in the output (reporters and logs)
    colors: true,

    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,

    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,

    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome'],

    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity
  })
}

Unit Test

import {Person} from "../greeter.js";

describe("Person FullName", () => {

    var person: Person;

    beforeEach(() => {
        person = new Person();
        person.setFirstName("Joe");
        person.setLastName("Smith");
        person.setFullName("Joe, Smith");
    });

    it("should concatenate first and last names", () => {
        expect(person.getFullName()).toBe("Joe, Smith");
    });

    it("should concatenate first and last names - incorrect", () => {
        expect(person.getFullName()).not.toBe("Joe, Doe");
    });

    it("should concatenate lastname first", () => {
        expect(person.getFullName(true)).toBe("Smith, Joe");
    });

    it("should not concatinate firstname first", () => {
        expect(person.getFullName(true)).not.toBe("Joe, Smith");
    });
});

Code editor or IDE name and version

Sublime Text v3

OS name and version

Windows

ArtemGovorov commented 8 years ago

You have mentioned you are using karma, did you mean wallaby or you have created the issue in a wrong repo? If you actually mean wallaby, could you please share your wallaby config file and a sample repo reproducing your issue?

piyush-avantsoft commented 8 years ago

I have updated my question description. Can you look it again?

ArtemGovorov commented 8 years ago

Your question doesn't seem to be related to wallaby.js.

ArtemGovorov commented 8 years ago

This repo is for wallaby.js related issues/questions. Your question is about karma test runner, you should probably ask it on StackOverflow. Given the details you've provided I suspect the issue is you've neither configured babel in your karma config, not are using some kind of module bundler (such as webpack or browserify) capable of handing ES6 modules (compiled to CommonJs by babel).