2017-05-05 140 views
0

我的環境設置非常像官方Angular2快速啓動,有一點不同:代替public/src/app,我有public/appAngular2測試,SystemJS無法加載模塊

當試圖測試ComponentViewChild

@ViewChild('profileModal') 
profileModal: ModalComponent; 

其在組件裝載下測試爲:

import { ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal'; 

npm test示出了這樣的錯誤:

05 05 2017 17:45:48.218:WARN [web-server]: 404: /base/ng2-bs3-modal/ng2-bs3-modal 
[1] Chrome 58.0.3029 (Mac OS X 10.12.2) ERROR 
[1] { 
[1]  "originalErr": { 
[1]  "__zone_symbol__currentTask": { 
[1]   "type": "microTask", 
[1]   "state": "notScheduled", 
[1]   "source": "Promise.then", 
[1]   "zone": "<root>", 
[1]   "cancelFn": null, 
[1]   "runCount": 0 
[1]  } 
[1]  }, 
[1]  "__zone_symbol__currentTask": { 
[1]  "type": "microTask", 
[1]  "state": "notScheduled", 
[1]  "source": "Promise.then", 
[1]  "zone": "<root>", 
[1]  "cancelFn": null, 
[1]  "runCount": 0 
[1]  } 
[1] } 

karma.config.js : [消隱爲了簡潔]

module.exports = function(config) { 
    var appBase = 'app/';  // transpiled app JS and map files 
    var appSrcBase = appBase;  // app source TS files 

    config.set({ 
    basePath: '.', 

    proxies: { 
     '/base/node_modules/': '/base/node_modules/' 
    }, 
    }) 
} 

我怎麼能告訴karma/base/npm_modules/ng2-bs3-modal/ng2-bs3-modal而不是/base/ng2-bs3-modal/ng2-bs3-modal加載,因爲它試圖。使用SystemJs而不是Webpack

回答

1

你應該把它放在karma.config文件的文件部分,像這樣:

files: [ 'node_modules/ng2-bs3-modal/ng2-bs3-modal.js' ] 

不知道如果你已經在你的配置文件部分,但爲了以防萬一,記住你可以通過你的systemjs配置讓它載入您的應用程序和它的依賴:

files: [ 
    // System.js for module loading 
    'node_modules/systemjs/dist/system.src.js', 

    // Load any lib not included in systemjs.config here, like zone.js 
    'node_modules/zone.js/dist/zone.js', 

    // RxJs 
    { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false }, 
    { pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false}, 
    // Paths loaded via module imports: 
    // Angular itself 
    { pattern: 'node_modules/@angular/**/*.js', included: false, watched: false }, 
    { pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false }, 

    { pattern: 'systemjs.config.js', included: false, watched: false }, 
    { pattern: 'systemjs.config.extras.js', included: false, watched: false }, 
    'karma-test-shim.js', 
] 

您可以參考這個post關於它的更多細節。