2017-12-04 21 views
0

私のアングル5アプリでは完全に機能するjQueryを使用していますが、カルマテストに問題があります。カルマテストでjQueryエラーが定義されていません

import { ElementRef } from '@angular/core'; 
declare var jQuery: any; 

export class Item { 

constructor(private element: ElementRef) { 
    this.init(); 
} 

private init() { 
    this.$item = jQuery(this.element.nativeElement); 
... 

エラー

にReferenceError:jQueryの定義されていません。

package.json

"dependencies": { 
    "jquery": "3.1.1" 
} 

私は私のkarma.confにjqueryのを追加したが、それは助けにはなりませんでした。

files: [ 
     'node_modules/core-js/client/shim.js', 
     'node_modules/systemjs/dist/system.src.js', 
     'node_modules/zone.js/dist/zone.js', 
     'node_modules/zone.js/dist/proxy.js', 
     'node_modules/zone.js/dist/sync-test.js', 
     'node_modules/zone.js/dist/jasmine-patch.js', 
     'node_modules/zone.js/dist/async-test.js', 
     'node_modules/zone.js/dist/fake-async-test.js', 
     'node_modules/tslib/tslib.js', 
     'node_modules/jquery/dist/jquery.js', 

     {pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false }, 
     {pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false }, 
     {pattern: '../karma-test-shim.js', included: true, watched: true}, 
     {pattern: 'node_modules/@angular/**/*.js', included: false, watched: false}, 
     {pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false}, 
     {pattern: 'node_modules/@ng-idle/core/bundles/core.umd.js', included: false, watched: false}, 
     {pattern: 'node_modules/bowser/bowser.js', included: false, watched: false}, 
     {pattern: 'node_modules/bootstrap/dist/js/bootstrap.js', included: false, watched: false}, 
     {pattern: 'node_modules/tslib/tslib.js', included: false, watched: false}, 
     {pattern: 'node_modules/jquery/dist/jquery.js', included: false, watched: false} 
    ], 
    proxies: { 
     "/node_modules/": "../../node_modules/" 
    }, 
    autoWatch: true, 
    browsers: ['PhantomJS', 'Chrome', 'HeadlessChrome'], 
    singleRun: false 
}); 
}; 

お手伝いできますか?

ありがとうございます。

files: [ 
     ..... 
     'node_modules/jquery/dist/jquery.js', 

     ..... 
     {pattern: 'node_modules/jquery/dist/jquery.js', included: false, watched: false} 
    ], 

あなたはそれを追加した二回目は、あなたが明示的にそうしないと述べている:

答えて

0

はあなたが二回にjqueryのを追加したようkarma.conf.js

module.exports = function(config) { 
    config.set({ 
    files: [ 
     'path_to/jquery.js' 
     ... 
    ], 
    }); 
}; 
0

jQueryパスが見える含めますそれを含める。私はあなたがこの2行目を削除する必要があると思います。

関連する問題