簡體   English   中英

在使用Angular2 beta和SystemJS的Karma單元測試中加載angular2-polyfilles.js時出現_setAsap錯誤

[英]_setAsap error when loading angular2-polyfilles.js in Karma unit test with Angular2 beta and SystemJS

運行業力單元測試時,出現以下錯誤:

Chrome 47.0.2526(Linux 0.0.0)錯誤
未捕獲的TypeError:無法讀取未定義的屬性'_setAsap'
評估path / node_modules / angular2 / bundles / angular2-polyfills.min.js
加載路徑/node_modules/angular2/bundles/angular2-polyfills.min.js時出錯

karma.conf.js包含以下內容:

// Karma configuration
// Generated on Tue Dec 08 2015 14:19:08 GMT-0600 (CST)
module.exports = function(config) {
    config.set({
        // base path that will be used to resolve all patterns (eg. files, exclude)
        basePath: '../',
        files: [
            'node_modules/angular2/bundles/angular2-polyfills.min.js',
            'node_modules/es6-shim/es6-shim.js',
            'node_modules/systemjs/dist/system.js',
            'node_modules/rxjs//Rx.js',
            'node_modules/angular2/bundles/angular2.min.js',
            'dist/components/uploader.js',
            'dist/components/uploader.spec.js'
        ],
        ...

uploader.js是TypeScript編譯的JavaScript文件,是Angular2組件。 Uploader.spec.js是單元測試。 我使用Karma,SystemJS和Angular2 beta來嘗試設置單元測試。

當查看_angular2_polyfills.js_時, _setAsap似乎指向模塊es6-promise 但是,即使我將node_modules/es6-promise/dist/es6-promise.js添加到文件列表中,也無法正常工作。

因此,我遇到了類似的問題,必須將其添加到我的system.conf.js文件中:

System.config({
    paths: {
        'agular2-polyfills': 'node_modules/angular2/bundles/angular2-polyfills.js',
        'typescript': 'node_modules/typescript/lib/typescript.js',
        'systemjs': 'node_modules/systemjs/dist/system.js',
        'system-polyfills': 'node_modules/systemjs/dist/system-polyfills.js',
        'es6-module-loader': 'node_modules/es6-module-loader/dist/es6-module-loader.js'
    },
    map: {
        angular2: 'node_modules/angular2',
        rxjs: 'node_modules/rxjs',
        crypto: '@empty'// this fixed my last issue
    },
    meta: {
        'path/to/components/*': {
            format: 'register'
        }
    }
});

如果我在瀏覽了幾個堆棧問題並閱讀了config文檔后沒記錯的話(我不聲稱自己是systemjs ninja ),那么我來到了這個解決方案,但是我不記得它的某些原因,除了它具有與必須使用業力加載所有內容有關。

我的karma.conf文件數組:

// list of files / patterns to load in the browser
    files: [
      'node_modules/reflect-metadata/Reflect.js',
      '*.spec.js',
      '**/*.spec.js',
      '**/**/*.spec.js'
    ]

和karma.conf systemjs配置:

systemjs: {
    // Path to your SystemJS configuration file 
    configFile: 'system.conf.js',

    // Patterns for files that you want Karma to make available, but not loaded until a module requests them. eg. Third-party libraries. 
    serveFiles: [
        'client/**/*.js',
        'server/**/*.js',
    ],

    // SystemJS configuration specifically for tests, added after your config file. 
    // Good for adding test libraries and mock modules 
    config: {
        transpiler: null,
        defaultJSExtensions: true
    },

    meta: {
        'angular2/angular2':{
            format: 'register'
        }
    }
},

重要說明這可能不是最好的方法,甚至不是最好的方法,但這就是我的工作方式。 我尚未在項目的這一部分進行重構階段,因為在完成項目的第一階段之后 ,我將進行此操作。

祝好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM