2017-06-28 6 views
0

テストスクリプトにtypescriptクラスをインポートしようとしたときにエラーが発生しました。角2/4カルマテスト

import { ApiResponseTimeRepository } from './ApiResponseTimeRepository'; 


describe('testing test',() => { 
    it('should pass',() => { 
     expect(1 + 1).toBe(2); 
    }); 
}); 

しかし、私は、私はUncaught ReferenceError: exports is not defined at TestRepositories.spec.js:2を取得し、テストを実行すると:これは私が何もしませんが、クラスをインポートしようとすると、簡単なテストを書いた私のkarma.conf.js

// Karma configuration 
// Generated on Mon Jun 12 2017 14:21:41 GMT+0200 (Central European Daylight Time) 

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

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


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


     // list of files/patterns to load in the browser 
     files: [ 
      { pattern: '**/*.spec.ts' } 
     ], 

     // 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: { 
      '**/*.ts': ['typescript'] 
     }, 

     // 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, 

     mime: { 
      'text/x-typescript': ['ts', 'tsx'] 
     } 
    }); 
}; 

です。

インポート部分を省略するとテストが正常に機能するので、タイプスクリプトのトランスリンギングに問題があるとわかりましたので、karma-typescript-preprocessorをインストールしましたが、エラーが表示され続けます。問題であると想定されるのは?ケースの誰に

+0

karma.conf.jsファイルが役に立ちます。 –

+0

これは '.ts'ですが、' .js'に転送されます。 – Norgul

答えて

0

は同じ問題を抱えている、私はこのパッケージをインストールすることによってそれを解決してきました:設定するには、karma-typescriptと、次の指示を `私は仕様のため、` .ts`拡張子を使用して考えて

関連する問題