错误: :PhantomJS中不存在fetch()方法

问题描述 投票:1回答:1

我正在使用PhantomJS来运行测试。

并得到以下错误:

错误:: fetch()方法不存在

这是karma.config.js文件:

var webpackConfig = require('./webpack.config.js');

    module.exports = config => {
      config.set({
        basePath: '',
        frameworks: ['jasmine'],
        files: ['node_modules/babel-polyfill/dist/polyfill.js','./src/components/**/*.spec.ts'],
        preprocessors: {
          './src/components/**/*.spec.ts': ['webpack']
        },
        mime: {
          'text/x-typescript': ['ts', 'tsx']
        },
        webpack: webpackConfig,
        reporters: ['progress'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['PhantomJS'],
        singleRun: false,
        webpackMiddleware: {
          noInfo: true
        },
        concurrency: Infinity
      });
    };
testing webpack phantomjs karma-jasmine
1个回答
1
投票

尝试将whatwg-fetch polyfill添加到karma.config.js中

files: [
      'node_modules/whatwg-fetch/fetch.js',
      ...
    ]
© www.soinside.com 2019 - 2024. All rights reserved.