简体   繁体   English

无法在_normalizeProvider中读取未定义的因果报应角度2错误

[英]Karma angular 2 error cannot read foreach of undefined at _normalizeProvider

I have some issue when I trying to test angular 2 with karma runner and got this error: http://prntscr.com/awsmor 当我尝试使用业力赛跑者测试angular 2并收到此错误时,我遇到一些问题: http : //prntscr.com/awsmor

I don't know what it this (got some errors when I update karma/node/grunt-karma). 我不知道这是什么(我更新karma / node / grunt-karma时遇到一些错误)。 First got error with undefined character in headers (karma socket) after that about undefined forEach at _normalize. 关于_normalize中的forEach的未定义,首先在标头(因果套接字)中出现未定义字符的错误。

I don't have any idea how I can fix it and where to looking. 我不知道如何修复它以及在哪里寻找。 Maybe someone can help me? 也许有人可以帮我吗?

My Karma.conf // Karma configuration 我的Karma.conf // Karma配置

module.exports = function(config) {


  config.set({
    basePath: '.',
    frameworks: ['jasmine'],
    plugins: [
      'karma-jasmine',
      'karma-chrome-launcher',
      'karma-coverage',
    ],
    colors: true,

    autoWatch: true,
    // don't shut down phantom instance for 1 minute
    // because should be able to reuse the instance
    // in one testrun. E.g. run unit tests against
    // sources and minified artifacts
    browserNoActivityTimeout: 60000,

    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: ['Chrome'],

    logLevel: config.LOG_ERROR,

    preprocessors: {
      'built/production/**/!(*spec).js': ['coverage']
    },

    files: [{
      pattern: 'node_modules/angular2/bundles/angular2-polyfills.js',
      included: true,
      watched: true
    }, {
      pattern: 'node_modules/systemjs/dist/system.src.js',
      included: true,
      watched: true
    }, {
      pattern: 'node_modules/rxjs/bundles/Rx.js',
      included: true,
      watched: true
    }, {
      pattern: 'node_modules/angular2/bundles/angular2.dev.js',
      included: true,
      watched: true
    },
    {
     pattern: 'node_modules/angular2/bundles/http.dev.js',
     included: true,
     watched: true
   },
    {
      pattern: 'node_modules/angular2/bundles/router.dev.js',
      included: true,
      watched: true
    }, {
      pattern: 'node_modules/angular2/bundles/testing.dev.js',
      included: true,
      watched: true
    }, {
      pattern: 'karma-test-shim.js',
      included: true,
      watched: true
    }, {
      pattern: 'src/**/*.ts',
      included: false,
      watched: false
    }, {
      pattern: 'built/production/**/*.js',
      included: false,
      watched: true
    }, {
      pattern: 'built/production/**/*.js.map',
      included: false,
      watched: false
    }],

    proxies: {
      // required for component assests fetched by Angular's compiler
      '/src/': './src/'
    },
    port: 9876,
    // singleRun: true,

    reporters: ['progress', 'dots', 'coverage'],
    coverageReporter: {
      reporters: [{
        type: 'html'
      }]
    },


  });
};

Karma test.shim 业力测试垫片

// Tun on full stack traces in errors to help debugging
Error.stackTraceLimit = Infinity;


jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;

// // Cancel Karma's synchronous start,
// // we will call `__karma__.start()` later, once all the specs are loaded.
__karma__.loaded = function() {};


System.config({
  packages: {
    'built': {
      defaultExtension: false,
      format: 'register',
      map: Object.keys(window.__karma__.files).
            filter(onlyAppFiles).
            reduce(function createPathRecords(pathsMapping, appPath) {
              // creates local module name mapping to global path with karma's fingerprint in path, e.g.:
              // './hero.service': '/base/src/app/hero.service.js?f4523daf879cfb7310ef6242682ccf10b2041b3e'
              var moduleName = appPath.replace(/^\/built\//, './').replace(/\.js$/, '');
              pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath]
              return pathsMapping;
            }, {})

      }
    }
});

System.import('angular2/testing').then(function(testing) {
    return System.import('angular2/src/platform/browser/browser_adapter').then(function(providers) {
        testing.setBaseTestProviders(providers.TEST_BROWSER_PLATFORM_PROVIDERS,
            providers.TEST_BROWSER_APPLICATION_PROVIDERS);
    });
}).then(function() {
  return Promise.all(
    Object.keys(window.__karma__.files) // All files served by Karma.
    .filter(onlySpecFiles)
    // .map(filePath2moduleName)        // Normalize paths to module names.
    .map(function(moduleName) {
      // loads all spec files via their global module names (e.g. 'base/src/app/hero.service.spec')
      return System.import(moduleName);
    }));
})
.then(function() {
  __karma__.start();
}, function(error) {
  __karma__.error(error.stack || error);
});


function filePath2moduleName(filePath) {
  return filePath.
           replace(/^\//, '').              // remove / prefix
           replace(/\.\w+$/, '');           // remove suffix
}


function onlyAppFiles(filePath) {
  return /^\/built\/.*\.js$/.test(filePath)
}


function onlySpecFiles(path) {
  return /.spec\.js$/.test(path);
}
testing.setBaseTestProviders(
browser.TEST_BROWSER_PLATFORM_P‌​ROVIDERS, browser.TEST_BROWSER_APPLICATION_PROVIDERS); 

rc1 deprecated TEST_BROWSER_PLATFORM_PROVIDERS I believe so commenting it out helped rc1已弃用TEST_BROWSER_PLATFORM_PROVIDERS,我相信将其注释掉对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 2测试错误无法读取未定义的属性“ forEach” - Angular 2 Testing Error Cannot read property 'forEach' of undefined TypeError:无法读取未定义的属性(读取'forEach) - TypeError: Cannot read properties of undefined (reading 'forEach) 角业力测试:类型错误:无法读取 null 的属性“路径” - Angular karma testing: TypeError: Cannot read property 'path' of null Jasmine - 无法读取undefined的属性'controls' - Angular 6 - Jasmine - Cannot read property 'controls' of undefined - Angular 6 使用Jest进行测试 - TypeError:无法读取未定义的属性'forEach' - Testing with Jest - TypeError: cannot read property 'forEach' of undefined 类型错误:无法读取未定义的属性 Angular - typeError: cannot read properties of undefined Angular Angular 测试:无法读取未定义的属性“图像” - Angular Testing: Cannot read property 'images' of undefined Angular 测试 - 类型错误:无法读取未定义的属性“7” - Angular Testing - TypeError: Cannot read property '7' of undefined 通过spy / karma模拟服务类时无法读取未定义的属性“ doc” - Cannot read property 'doc' of undefined when mocking service class through spy/karma 错误“无法读取未定义的属性“数据”” - Error 'Cannot read property 'data' of undefined'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM