Angular2测试:'未处理的承诺拒绝:','无法加载strategyTables.html'

时间:2017-05-21 11:22:38

标签: angular testing webpack karma-runner

我在使用templateUrl测试组件时发现了这个错误。我想知道webpasck&test测试是否有问题。我不知道如何修复它。谢谢提前!

错误:'未处理的承诺拒绝:','无法加载strategyTables.html',&#39 ;;区域:',' ProxyZone',&#39 ;;任务:',' Promise.then',&#39 ;;值:','无法加载strategyTables.html',未定义 错误:错误{originalStack:'错误:未捕获(承诺):无法加载strategyTables.html



//karma.config.js
// Karma configuration

var webpackConfig = require('./webpack.test');
module.exports = function(config) {
  config.set({
    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '.',
    // 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: './karma-shim.js', watched: false}
      ],

    // 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: {
      './karma-shim.js': ['webpack']
    },
    webpack: webpackConfig,
    plugins:[
      'karma-jasmine',
      'karma-chrome-launcher',
      require("karma-webpack")
    ],
    proxies:{
      //http://localhost:3000/#/pages/strategys/strategytables
      "/app/": "base/src/app"
    },
    // 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
  })
}






//karma-shim,js
Error.stackTraceLimit = Infinity;

require('reflect-metadata');
require('zone.js/dist/zone');
require('zone.js/dist/proxy');
require('zone.js/dist/sync-test');
require('zone.js/dist/jasmine-patch');
require('zone.js/dist/async-test');
require('zone.js/dist/fake-async-test');


var appContext = require.context('./src',true,/\.spec\.ts/);
appContext.keys().forEach(appContext);


var testing = require('@angular/core/testing');
var testingBrowser = require('@angular/platform-browser-dynamic/testing');
testing.TestBed.initTestEnvironment(testingBrowser.
    BrowserDynamicTestingModule,
    testingBrowser.platformBrowserDynamicTesting());






//webpack.test.js
module.exports = {
  devtool: 'cheap-module-eval-source-map',
  resolve: {
    extensions: ['.ts','.js']
  },

  entry: {
   },

  module: {
    loaders: [
      //��.ts��β���ļ�ʹ�� TypeScript loader
      {test: /.ts$/,loader: 'awesome-typescript-loader'},
      {
        test:/\.html$/,
        loader: 'html'
      },
      {
        test:/\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
        loader: 'null'
      },
      {
        test:/\.css$/,
        loader: 'null'
      }
    ]
  }
  
}




1 个答案:

答案 0 :(得分:0)

在使用Unhandled Promise Rejection测试组件并为其分配原始html时,我遇到了相同的templateURL错误。我相信这是因为它试图加载一个不存在的html文件。使用原始html的template解决了这个问题。

我认为所有这个错误意味着无法找到指定的html文件,因此请确保路​​径正确并且所需的html文件位于正确的位置。