Angular2 测试 : 'Unhandled Promise rejection:' , 'Failed to load strategyTables.html'

标签 angular testing webpack karma-runner

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

错误:'未处理的 promise 拒绝:','无法加载 strategyTables.html',';区域:','ProxyZone',';任务:', 'Promise.then', ';值:','无法加载 strategyTables.html',未定义 错误:错误{originalStack:'错误:未捕获( promise ):无法加载 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'
      }
    ]
  }
  
}

最佳答案

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

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

关于Angular2 测试 : 'Unhandled Promise rejection:' , 'Failed to load strategyTables.html',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44096274/

相关文章:

angular - 无法绑定(bind)到 'ngModel',因为它不是 'p-autoComplete' 的已知属性

javascript - 通过管道同时允许多个过滤器值 - Angular

testing - 如何测试 SSL 在 dev 上的设置和配置是否正确?

c# - 依赖 HTTPContext 的 MVC 测试操作

javascript - Vue.js 模板中的静态图像 src

为每个 ts 文件生成 TypeScript 2.1 async/await ES5 __awaiter 和 __generator

angular - 错误 NG2003 : No suitable injection token for parameter 'id' of class

Angular 形式 : "No value accessor for ..."

python - 在 Python 的主线程中捕获线程的异常

vue.js - 关键依赖 : the request of a dependency is an expression, vue.js